将每个工作表保存为不同的PDF文件
Contents
[
Hide
]
Aspose.Cells for Python via .NET支持将包含图像、图表等的XLS文件转换为PDF文档。Aspose.Cells for Python via .NET可独立工作,将电子表格转换为PDF,您无需使用Aspose.PDF for .NET进行转换。转换不需要软件创建或使用任何临时文件,整个过程可以在内存中完成。
将每个工作表保存为不同的PDF文件
如果您需要保存模板 Excel 文件中的每个工作表以生成不同的 PDF 文件,这很容易实现。您可以尝试逐个将一个工作表索引设置为 PdfSaveOptions.sheet_set 选项以渲染为 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 | |
from aspose.cells.rendering import SheetSet | |
# 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(".") | |
# Get the Excel file path | |
filePath = dataDir + "input.xlsx" | |
# Instantiage a new workbook and open the Excel, File from its location | |
workbook = Workbook(filePath) | |
# Get the count of the worksheets in the workbook | |
sheetCount = len(workbook.worksheets) | |
# Define PdfSaveOptions | |
pdfSaveOptions = PdfSaveOptions() | |
# Take Pdfs of each sheet | |
for j in range(sheetCount): | |
ws = workbook.worksheets[j] | |
# set worksheet to output | |
sheetSet = SheetSet([ws.index]) | |
pdfSaveOptions.sheet_set = sheetSet | |
workbook.save(dataDir + "worksheet-" + ws.name + ".out.pdf", pdfSaveOptions) |
如果您的电子表格包含公式,最好在将电子表格呈现为PDF格式之前调用 Workbook.calculate_formula()。这样做将确保重新计算依赖于公式的值,并在PDF中呈现正确的值。