Rendi sequenza di pagine usando le proprietà PageIndex e PageCount di ImageOrPrintOptions
Possibili Scenari di Utilizzo
È possibile rendere una sequenza di pagine del file Excel in immagini utilizzando Aspose.Cells con le proprietà ImageOrPrintOptions.PageIndex e ImageOrPrintOptions.PageCount. Queste proprietà sono utili quando ci sono ad esempio migliaia di pagine nel foglio di lavoro ma si desidera renderne solo alcune. Questo non solo risparmierà tempo di elaborazione ma risparmierà anche l’utilizzo della memoria del processo di rendering.
Rendere la sequenza di pagine utilizzando le proprietà PageIndex e PageCount di ImageOrPrintOptions
Il seguente codice di esempio carica il file Excel di esempio e rende solo le pagine 4, 5, 6 e 7 utilizzando le proprietà ImageOrPrintOptions.PageIndex e ImageOrPrintOptions.PageCount. Ecco le pagine renderizzate generate dal codice.
Codice di Esempio
// 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"); | |
} |