将带有图像或图表的 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 之前的方法。这样做可确保重新计算公式相关值,并在 PDF 中呈现正确的值。