使用 ImageOrPrintOptions 的 PageIndex 和 PageCount 属性渲染页面序列
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 将 Excel 文件的一系列页面呈现为图像ImageOrPrintOptions.PageIndex和ImageOrPrintOptions.PageCount特性。当您的工作表中有很多页面(例如数千页)但您只想呈现其中的一些页面时,这些属性很有用。这不仅会节省处理时间,还会节省渲染过程的内存消耗。
使用 ImageOrPrintOptions 的 PageIndex 和 PageCount 属性渲染页面序列
下面的示例代码加载示例 Excel 文件并且只渲染第 4、5、6 和 7 页ImageOrPrintOptions.PageIndex和ImageOrPrintOptions.PageCount特性。这是代码生成的渲染页面。
![]() |
![]() |
---|---|
![]() |
![]() |
示例代码
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 | |
//Load the sample Excel file | |
Workbook wb = new Workbook(srcDir + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx"); | |
//Access the first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Specify image or print options | |
//We want to print pages 4, 5, 6, 7 | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setPageIndex(3); | |
opts.setPageCount(4); | |
opts.setImageType(ImageType.PNG); | |
//Create sheet render object | |
SheetRender sr = new SheetRender(ws, opts); | |
//Print all the pages as images | |
for (int i = opts.getPageIndex(); i < sr.getPageCount(); i++) | |
{ | |
sr.toImage(i, outDir + "outputImage-" + (i+1) + ".png"); | |
} |