无内容打印时输出空白页

可能的使用场景

如果工作表为空,则在将工作表导出为图像时 Aspose.Cells 将不会打印任何内容。您可以使用更改此行为ImageOrPrintOptions.OutputBlankPageWhenNothingToPrint财产。当你将它设置为真的,它将打印空白页。

无内容打印时输出空白页

以下示例代码创建一个空工作簿,其中包含一个空工作表,并在设置后将空工作表呈现为图像ImageOrPrintOptions.OutputBlankPageWhenNothingToPrint财产作为真的.因此,它会生成空白页,因为没有要打印的内容,如下所示。

待办事项:图片_替代_文本

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String outDir = Utils.Get_OutputDirectory();
// Create workbook
Workbook wb = new Workbook();
// Access first worksheet - it is empty sheet
Worksheet ws = wb.getWorksheets().get(0);
// Specify image or print options
// Since the sheet is blank, we will set
// OutputBlankPageWhenNothingToPrint to true
// So that empty page gets printed
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setImageType(ImageType.PNG);
opts.setOutputBlankPageWhenNothingToPrint(true);
// Render empty sheet to png image
SheetRender sr = new SheetRender(ws, opts);
sr.toImage(0, outDir + "OutputBlankPageWhenNothingToPrint.png");