Convert XLS File with Images or Charts to PDF
Contents
[
Hide
]
Aspose.Cells for Python via .NET supports converting XLS files that contain images and charts to PDF documents. Aspose.Cells for Python via .NET API can work independently to convert a spreadsheet to PDF: Aspose.PDF for .NET is not required for the conversion. The process can be done in memory as the process does not depend on temporary or intermediary XML files. This means that large Excel files, for example, ones containing images, charts, and other drawing objects, can be converted quickly and efficiently.
Sample Code
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 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(".") | |
try: | |
# Get the template excel file path. | |
designerFile = dataDir + "SampleInput.xls" | |
# Specify the pdf file path. | |
pdfFile = dataDir + "Output.out.pdf" | |
# Open the template excel file | |
wb = Workbook(designerFile) | |
# Save the pdf file. | |
wb.save(pdfFile, SaveFormat.PDF) | |
except Exception as e: | |
print(str(e)) | |
input() |
If the spreadsheet contains formulas, it is best to call the Workbook.calculate_formula method just before rendering to PDF. Doing so ensures that formula dependent values are recalculated, and the correct values are rendered in the PDF.