Render Sequence of Pages using PageIndex and PageCount Properties of ImageOrPrintOptions
Possible Usage Scenarios
You can render a sequence of pages of your Excel file to images by using Aspose.Cells for Python via .NET with ImageOrPrintOptions.page_index and ImageOrPrintOptions.page_count properties. These properties are useful when there are so many e.g. thousands of pages in your worksheet but you want to render some of them only. This will not only save the processing time but will also save the memory consumption of the rendering process.
Render Sequence of Pages using PageIndex and PageCount Properties of ImageOrPrintOptions
The following sample code loads the sample Excel file and renders only pages 4, 5, 6 and 7 using the ImageOrPrintOptions.page_index and ImageOrPrintOptions.page_count properties. Here are the rendered pages generated by the code.
Sample Code
from aspose.cells import Workbook | |
from aspose.cells.drawing import ImageType | |
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Source directory | |
sourceDir = RunExamples.Get_SourceDirectory() | |
# Output directory | |
outputDir = RunExamples.Get_OutputDirectory() | |
# Load the sample Excel file | |
wb = Workbook(sourceDir + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx") | |
# Access the first worksheet | |
ws = wb.worksheets[0] | |
# Specify image or print options | |
# We want to print pages 4, 5, 6, 7 | |
opts = ImageOrPrintOptions() | |
opts.page_index = 3 | |
opts.page_count = 4 | |
opts.image_type = ImageType.PNG | |
# Create sheet render object | |
sr = SheetRender(ws, opts) | |
# Print all the pages as images | |
for i in range(opts.page_index, sr.page_count): | |
sr.to_image(i, outputDir + "outputImage-" + str(i + 1) + ".png") |