[]
GcExcel Java允许用户在执行打印操作时保存工作表的草稿。
要在打印时配置草稿,请参阅以下示例代码。
// Create a new workbook and access the default worksheet
Workbook workbook = new Workbook();
IWorksheet sheet = workbook.getWorksheets().get(0);
// Set text.
sheet.getRange("A1:G10").setValue("Text");
// Add picture in worksheet.
FileInputStream stream = null;
try
{
stream = new FileInputStream("Pictures/logo.png");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
try
{
IShape picture = sheet.getShapes()
.addPicture(stream,ImageType.PNG,20,20,395,60);
}
catch (IOException ioe)
{
}
// Add header graphic.
FileInputStream stream1 = null;
try
{
stream1 = new FileInputStream("Pictures/logo.png");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
sheet.getPageSetup().setCenterHeader("&G");
sheet.getPageSetup().getCenterHeaderPicture().setGraphicStream(stream1,ImageType.PNG);
sheet.getPageSetup().getCenterHeaderPicture().setWidth(100);
sheet.getPageSetup().getCenterHeaderPicture().setHeight(13);
// Set print without graphics in page content area.
sheet.getPageSetup().setDraft(true);
// Save to a pdf file
workbook.save("Draft.pdf", SaveFileFormat.Pdf);