将所有工作表列放在单个页面上 PDF
Contents
[
Hide
]
有时您想要生成一个 PDF 文件,以将工作表的所有列放入一个页面。这PdfSaveOptions.setAllColumnsInOnePagePerSheet属性以非常易于使用的方式提供此功能。输出 PDF 页面的高度和宽度等复杂计算在内部处理,并基于工作表中的数据。
在单个页面上调整工作表列 PDF
PdfSaveOptions.setAllColumnsInOnePagePerSheet确保将工作表的所有列呈现到单个 PDF 页面,尽管行可能会扩展到多个页面,具体取决于工作表中的数据。
当给定的工作表有很多列时,呈现的 PDF 文件可能会以非常小的尺寸显示内容。在 Acrobat Reader 等查看应用程序中放大时,它仍然可读。
下面的示例代码显示了如何使用PdfSaveOptions.setAllColumnsInOnePagePerSheet属性呈现 100 列的大型工作表。
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FitAllWorksheetColumns.class); | |
// 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(SaveFormat.PDF); | |
// Set AllColumnsInOnePagePerSheet to true | |
saveOptions.setAllColumnsInOnePagePerSheet(true); | |
// Save Workbook to PDF fromart by passing the object of PdfSaveOptions | |
book.save(dataDir + "output.pdf", saveOptions); |
如果您的电子表格包含公式,最好调用工作簿.计算公式 方法在将电子表格呈现为 PDF 格式之前。这样做将确保重新计算公式相关值,并在 PDF 中呈现正确的值。