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

可能的使用场景

您可以使用 Aspose.Cells 和 ImageOrPrintOptions.PageIndexImageOrPrintOptions.PageCount 属性将 Excel 文件的一系列页面呈现为图像。当您的工作表中有成千上万页但您只想呈现其中一些时,这些属性是有用的。这不仅可以节省处理时间,还可以节省呈现过程中的内存消耗。

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

以下示例代码加载了sample Excel file并仅使用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-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
//Load the sample Excel file
Workbook wb = new Workbook(sourceDir + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx");
//Access the first worksheet
Worksheet ws = wb.Worksheets[0];
//Specify image or print options
//We want to print pages 4, 5, 6, 7
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.PageIndex = 3;
opts.PageCount = 4;
opts.ImageType = Drawing.ImageType.Png;
//Create sheet render object
SheetRender sr = new SheetRender(ws, opts);
//Print all the pages as images
for (int i = opts.PageIndex; i < sr.PageCount; i++)
{
sr.ToImage(i, outputDir + "outputImage-" + (i + 1) + ".png");
}