将所有工作表列调整到单个PDF页面
Contents
[
Hide
]
有时候,您希望生成一个PDF文件,将工作表的所有列适合一页。PdfSaveOptions.all_columns_in_one_page_per_sheet属性以一种非常易于使用的方式提供了这种功能。输出PDF的高度和宽度等复杂计算是在内部处理的,是基于工作表中的数据。
使工作表列适合单个PDF页面
PdfSaveOptions.all_columns_in_one_page_per_sheet确保工作表中的所有列都呈现在单个PDF页面上,尽管根据工作表中的数据,行可能会扩展到几页。
下面的示例代码显示了如何使用PdfSaveOptions.all_columns_in_one_page_per_sheet属性呈现一个包含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
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中呈现正确的值。