无内容打印时输出空白页
Contents
[
Hide
]
可能的使用场景
如果工作表为空,则在将工作表导出为图像时 Aspose.Cells 将不会打印任何内容。您可以使用更改此行为ImageOrPrintOptions.OutputBlankPageWhenNothingToPrint财产。当你将它设置为真的,它将打印空白页。
无内容打印时输出空白页
以下示例代码创建一个空工作簿,其中包含一个空工作表,并在设置后将空工作表呈现为图像ImageOrPrintOptions.OutputBlankPageWhenNothingToPrint财产作为真的.因此,它会生成空白页,因为没有要打印的内容,如下所示。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |