ImageOrPrintOptions の PageIndex および PageCount プロパティを使用したページのシーケンスのレンダリング
Contents
[
Hide
]
ImageOrPrintOptions の PageIndex および PageCount プロパティを使用したページのシーケンスのレンダリング
Aspose.Cells を使用して、Excel ファイルの一連のページを画像にレンダリングできます。ImageOrPrintOptions.PageIndexとImageOrPrintOptions.PageCountプロパティ。これらのプロパティは、ワークシートに非常に多くのページ (たとえば数千ページ) があり、その一部のみをレンダリングしたい場合に役立ちます。これにより、処理時間が節約されるだけでなく、レンダリング プロセスのメモリ消費も節約されます。
次のサンプル コードは、サンプル Excel ファイルを読み込み、ImageOrPrintOptions.PageIndexとImageOrPrintOptions.PageCountプロパティ。以下は、サンプル コードによって生成されたレンダリングされたページのイメージです。
![]() |
![]() |
---|---|
![]() |
![]() |
サンプルコード
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 |