ImageOrPrintOptionsのPageIndexおよびPageCountプロパティを使用してページのシーケンスをレンダリングする

ImageOrPrintOptionsのPageIndexおよびPageCountプロパティを使用したページのシーケンスをレンダリングする

Aspose.Cellsを使用してExcelファイルのページを画像にレンダリングするときに、ImageOrPrintOptions.PageIndex および ImageOrPrintOptions.PageCount プロパティが役立ちます。これらのプロパティを使用すると、ワークシートに何千ものページがある場合でも、一部のページのみをレンダリングしたい場合に便利です。これにより処理時間の節約だけでなく、レンダリングプロセスのメモリ消費も節約できます。

次のサンプルコードは、サンプルExcelファイルをロードし、ImageOrPrintOptions.PageIndex および ImageOrPrintOptions.PageCount プロパティを使用してページ4、5、6、7をレンダリングします。以下は、サンプルコードによって生成されたレンダリングされたページの画像です。

todo:image_alt_text todo:image_alt_text
todo:image_alt_text todo:image_alt_text

サンプルコード

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