ワークシートのすべての列を単一の PDF ページに収める
Contents
[
Hide
]
時々、ワークシートの全列を1ページに収めたPDFファイルを生成したいことがあります。PdfSaveOptions.AllColumnsInOnePagePerSheetプロパティはその機能を非常に簡単に使用できます。ワークシートのデータに基づいて、出力PDFの高さや幅などの複雑な計算は内部で処理されます。
ワークシートの列を単一の PDF ページに収める
PdfSaveOptions.AllColumnsInOnePagePerSheetは、ワークシート内のすべての列が1つのPDFページにレンダリングされることを保証します。ただし、ワークシートのデータに応じて、行が複数のページに拡張される場合があります。
以下のサンプルコードは、100列の大きなワークシートをレンダリングするためにPdfSaveOptions.AllColumnsInOnePagePerSheetプロパティを使用する方法を示しています。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create and initialize an instance of Workbook | |
Workbook book = new Workbook(dataDir + "TestBook.xlsx"); | |
// Create and initialize an instance of PdfSaveOptions | |
PdfSaveOptions saveOptions = new PdfSaveOptions(); | |
// Set AllColumnsInOnePagePerSheet to true | |
saveOptions.AllColumnsInOnePagePerSheet = 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.CalculateFormula() を呼び出すことが最善です。これにより、数式に依存する値が再計算され、PDFで正しい値がレンダリングされます。