ワークシートのすべての列を単一の PDF ページに収める
Contents
[
Hide
]
時々、ワークシートの全列を1ページに収めたPDFファイルを生成したいことがあります。PdfSaveOptions.all_columns_in_one_page_per_sheetプロパティはその機能を非常に簡単に使用できます。ワークシートのデータに基づいて、出力PDFの高さや幅などの複雑な計算は内部で処理されます。
ワークシートの列を単一の PDF ページに収める
PdfSaveOptions.all_columns_in_one_page_per_sheetは、ワークシート内のすべての列が1つのPDFページにレンダリングされることを保証します。ただし、ワークシートのデータに応じて、行が複数のページに拡張される場合があります。
以下のサンプルコードは、100列の大きなワークシートをレンダリングするためにPdfSaveOptions.all_columns_in_one_page_per_sheetプロパティを使用する方法を示しています。
This file contains hidden or 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
from aspose.cells import PdfSaveOptions, SaveFormat, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create and initialize an instance of Workbook | |
book = Workbook(dataDir + "TestBook.xlsx") | |
# Create and initialize an instance of PdfSaveOptions | |
saveOptions = PdfSaveOptions(SaveFormat.PDF) | |
# Set AllColumnsInOnePagePerSheet to true | |
saveOptions.all_columns_in_one_page_per_sheet = True | |
# Save Workbook to PDF fromart by passing the object of PdfSaveOptions | |
dataDir = dataDir + "output.out.pdf" | |
book.save(dataDir, saveOptions) |
あるワークシートに多くの列がある場合、レンダリングされたPDFファイルでは内容が非常に小さくなる場合があります。Acrobat Readerなどの閲覧アプリケーションで拡大するとまだ読める場合があります。
スプレッドシートに数式が含まれている場合、スプレッドシートをPDF形式にレンダリングする直前にWorkbook.calculate_formulaメソッドを呼び出すのが最適です。これにより、数式に依存する値が再計算され、PDFに正しい値がレンダリングされます。