每个 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); |
如果每张一页选项设置为真的,所有工作表内容将呈现为一个 PDF 页面。
如果您的电子表格包含公式,最好调用工作簿.CalculateFormula()就在将电子表格呈现为 PDF 之前。这可确保重新计算公式相关值,并在 PDF 中呈现正确的值。