限制生成的页面数量 将Excel转换为PDF
Contents
[
Hide
]
有时,您希望将一系列页面打印到输出PDF文件。Aspose.Cells for Python via .NET具有在将Excel电子表格转换为PDF文件格式时设置生成的页面数量的能力。
限制生成的页面数量
以下示例显示了如何将Microsoft Excel文件的页面范围(第3页和第4页)呈现为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(".") | |
# Open an Excel file | |
wb = Workbook(dataDir + "TestBook.xlsx") | |
# Instantiate the PdfSaveOption | |
options = PdfSaveOptions() | |
# Print only Page 3 and Page 4 in the output PDF | |
# Starting page index (0-based index) | |
options.page_index = 3 | |
# Number of pages to be printed | |
options.page_count = 2 | |
# Save the PDF file | |
wb.save(dataDir + "outPDF1.out.pdf", options) |
如果电子表格包含公式,最好在将其渲染为PDF之前调用Workbook.calculate_formula方法。这样做可以确保重新计算基于公式的值,并在输出文件中呈现正确的值。