Convert XLS File with Images or Charts to PDF
Contents
[
Hide
]
Aspose.Cells supports converting XLS files that contain images and charts to PDF documents. Aspose.Cells for .NET 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Get the template excel file path. | |
string designerFile = dataDir + "SampleInput.xls"; | |
// Specify the pdf file path. | |
string pdfFile = dataDir + "Output.out.pdf"; | |
// Open the template excel file | |
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(designerFile); | |
// Save the pdf file. | |
wb.Save(pdfFile, SaveFormat.Pdf); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
Console.ReadLine(); | |
} |
If the spreadsheet contains formulas, it is best to call the Workbook.CalculateFormula method just before rendering to PDF. Doing so ensures that formula dependent values are recalculated, and the correct values are rendered in the PDF.