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

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

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

次のサンプル コードは、サンプル Excel ファイルを読み込み、ImageOrPrintOptions.PageIndexImageOrPrintOptions.PageCountプロパティ。以下は、サンプル コードによって生成されたレンダリングされたページのイメージです。

todo:画像_代替_文章 todo:画像_代替_文章
todo:画像_代替_文章 todo:画像_代替_文章

サンプルコード

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