将Excel工作表渲染为一份PDF页面 Excel转PDF转换
Contents
[
Hide
]
当处理大型Microsoft Excel文件(例如具有许多工作表,每个工作表有50列和300多行数据)时,您可能希望PDF输出每个工作表显示一页,而不考虑工作表的大小。这意味着每一页可能具有截然不同的页面大小。这可以通过使用Aspose.Cells for .NET来实现。
请查看以下示例代码,将多个工作表的Excel文件转换为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
// 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); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Implement one page per worksheet option | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.OnePagePerSheet = true; | |
// Save the PDF file | |
workbook.Save(dataDir+ "OutputFile.out.pdf", pdfSaveOptions); |
如果OnePagePerSheet选项设置为true,则所有工作表内容将呈现为一个PDF页面。
如果您的电子表格包含公式,最好在将电子表格呈现为PDF之前调用Workbook.CalculateFormula()。这将确保重新计算公式相关值,并在PDF中呈现正确的值。