将Excel工作表渲染为一份PDF页面 Excel转PDF转换
Contents
[
Hide
]
当处理大型Microsoft Excel文件时(例如一个包含许多工作表的工作簿,每个工作表都有50列和300多行数据),您可能希望PDF输出每个工作表显示一页,而不管工作表的大小如何。这意味着每个页面可能具有完全不同的页面大小。可以使用Aspose.Cells for Python via .NET API来实现这一点。
请查看以下示例代码,将多个工作表的Excel文件转换为PDF。
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, 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(".") | |
# Initialize a new Workbook | |
# Open an Excel file | |
workbook = Workbook(dataDir + "input.xlsx") | |
# Implement one page per worksheet option | |
pdfSaveOptions = PdfSaveOptions() | |
pdfSaveOptions.one_page_per_sheet = True | |
# Save the PDF file | |
workbook.save(dataDir + "OutputFile.out.pdf", pdfSaveOptions) |
如果PdfSaveOptions.one_page_per_sheet 选项设置为true,则所有工作表内容将被渲染到一个PDF页面中。
如果您的电子表格包含公式,最好在将电子表格渲染为PDF之前调用Workbook.calculate_formula 方法。这可以确保重新计算基于公式的值,并在PDF中呈现正确的值。