限制生成的页数 - Excel 到 PDF 的转换
Contents
[
Hide
]
有时,您希望将一系列页面打印到输出 PDF 文件中。 Aspose.Cells 可以设置将 Excel 电子表格转换为 PDF 时生成多少页的限制。
限制生成的页数
以下示例显示如何将 Microsoft Excel 文件中的一系列页面(3 和 4)呈现为 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(LimitNumberofPagesGenerated.class); | |
// Open an Excel file | |
Workbook wb = new Workbook(dataDir + "TestBook.xlsx"); | |
// Instantiate the PdfSaveOption | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// Print only Page 3 and Page 4 in the output PDF | |
// Starting page index (0-based index) | |
options.setPageIndex(2); | |
// Number of pages to be printed | |
options.setPageCount(2); | |
// Save the PDF file | |
wb.save(dataDir + "outPDF1.pdf", options); |
如果电子表格包含公式,最好调用[工作簿.计算公式](https://reference.aspose.com/cells/java/com.aspose.cells/workbook#calculateFormula()就在将其呈现为 PDF 格式之前。这样做可确保重新计算公式相关值,并在输出文件中呈现正确的值。