Eseguire il rendering della sequenza di pagine utilizzando le proprietà PageIndex e PageCount di ImageOrPrintOptions
Contents
[
Hide
]
Eseguire il rendering della sequenza di pagine utilizzando le proprietà PageIndex e PageCount di ImageOrPrintOptions
È possibile eseguire il rendering di una sequenza di pagine del file Excel in immagini utilizzando Aspose.Cells conImageOrPrintOptions.PageIndex eImageOrPrintOptions.PageCount proprietà. Queste proprietà sono utili quando ci sono così tante, ad esempio migliaia di pagine nel tuo foglio di lavoro, ma vuoi renderizzare solo alcune di esse. Ciò non solo salverà il tempo di elaborazione, ma salverà anche il consumo di memoria del processo di rendering.
Il seguente codice di esempio carica il file Excel di esempio ed esegue il rendering solo delle pagine 4, 5, 6 e 7 utilizzando ilImageOrPrintOptions.PageIndexeImageOrPrintOptions.PageCount proprietà. Di seguito sono riportate le immagini delle pagine renderizzate generate dal codice di esempio.
![]() |
![]() |
---|---|
![]() |
![]() |
Codice d’esempio
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
source_directory = "Examples/SampleFiles/SourceDirectory/" | |
output_directory = "Examples/SampleFiles/OutputDirectory/" | |
# Load the Sample Workbook | |
workbook = Workbook(source_directory + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.getWorksheets().get(0) | |
# Specify image or print options | |
# We want to print pages 4, 5, 6, 7 | |
imageOrPrintOptions = ImageOrPrintOptions() | |
imageOrPrintOptions.setPageIndex(3) | |
imageOrPrintOptions.setPageCount(4) | |
imageOrPrintOptions.setImageFormat(ImageFormat.getPng()) | |
# Create sheet render object | |
sheetRender = SheetRender(worksheet, imageOrPrintOptions) | |
# Print all the pages as images | |
i = imageOrPrintOptions.getPageIndex() | |
while i < sheetRender.getPageCount(): | |
sheetRender.toImage(i, output_directory + "outputImage-" + str(i+1) + ".png") | |
i += 1 |