使用 ImageOrPrintOptions 的 PageIndex 和 PageCount 属性按顺序呈现页面
Contents
[
Hide
]
可能的使用场景
您可以使用 Aspose.Cells 和 ImageOrPrintOptions.PageIndex 和 ImageOrPrintOptions.PageCount 属性将 Excel 文件的一系列页面呈现为图像。当您的工作表中有成千上万页但您只想呈现其中一些时,这些属性是有用的。这不仅可以节省处理时间,还可以节省呈现过程中的内存消耗。
使用ImageOrPrintOptions的PageIndex和PageCount属性呈现页面序列
以下示例代码加载了sample Excel file并仅使用ImageOrPrintOptions.PageIndex和ImageOrPrintOptions.PageCount属性呈现了页面4、5、6和7。以下是代码生成的呈现页面。
示例代码
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-.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"); | |
} |