将带有图像或图表的XLS文件转换为PDF
Contents
[
Hide
]
Aspose.Cells支持将包含图像和图表的XLS文件转换为PDF文档。Aspose.Cells for .NET可以独立地工作,将电子表格转换为PDF,无需使用Aspose.PDF for .NET进行转换。该过程可以在内存中完成,不依赖于临时或中间XML文件。这意味着可以快速高效地转换大型Excel文件,例如包含图像、图表和其他绘图对象的文件。
示例代码
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(); | |
} |
如果电子表格中包含公式,最好在呈现到PDF之前调用 Workbook.CalculateFormula 方法。这样做可以确保基于公式的值被重新计算,并在PDF中呈现正确的值。