使用 ImageOrPrintOptions 的 PageIndex 和 PageCount 属性按顺序呈现页面

可能的使用场景

您可以使用 Aspose.Cells 的 ImageOrPrintOptions.PageIndexImageOrPrintOptions.PageCount 属性将 Excel 文件的页面序列渲染为图像。当工作表中有很多(例如成千上万)页,但您只想渲染其中的一些页时,这些属性将非常有用。这不仅可以节省处理时间,还可以节省渲染过程的内存消耗。

使用ImageOrPrintOptions的PageIndex和PageCount属性呈现页面序列

以下示例代码加载了 示例 Excel 文件,并仅使用 ImageOrPrintOptions.PageIndexImageOrPrintOptions.PageCount 属性渲染页面 4、5、6 和 7。以下是代码生成的渲染页面。

todo:image_alt_text todo:image_alt_text
todo:image_alt_text todo:image_alt_text

示例代码

// 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");
}