将指定的工作表保存为 PDF
默认情况下,Aspose.Cells 将所有 可见 的工作表保存到 PDF 文件中。使用 PdfSaveOptions.SheetSet 选项,您可以将指定的工作表保存到 PDF 文件中。例如,您可以保存活动工作表到 PDF,保存所有工作表(包括可见和隐藏的工作表)到 PDF,将自定义多个工作表保存到 PDF。
将活动工作表保存为 PDF
如果您只想将活动工作表导出为 PDF,则可以通过将 SheetSet.Active 传递给 PdfSaveOptions.SheetSet 选项来实现。
工作表 Sheet2
是源文件sheetset-example.xlsx的活动工作表。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set active sheet to output | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setSheetSet(SheetSet.getActive()); | |
// Save the pdf file with PdfSaveOptions | |
wb.save("output.pdf", pdfSaveOptions); |
将所有工作表保存为 PDF
SheetSet.Visible 指示工作簿中的可见工作表,SheetSet.All 指示工作簿中包括可见工作表和隐藏/不可见工作表。如果您想将所有工作表导出为 PDF,只需将 SheetSet.All 传递给 PdfSaveOptions.SheetSet 选项。
源文件sheetset-example.xlsx包含所有四个工作表,其中隐藏了工作表Sheet3
。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set all sheets to output | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setSheetSet(SheetSet.getAll()); | |
// Save the pdf file with PdfSaveOptions | |
wb.save("output.pdf", pdfSaveOptions); |
将指定的工作表保存为 PDF
如果要将所需/自定义的多个工作表导出为 PDF,可以通过将多个工作表索引传递给 PdfSaveOptions.SheetSet 选项来实现。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set custom multiple sheets(Sheet1, Sheet3) to output | |
SheetSet sheetSet = new SheetSet(new int[] { 0, 2 }); | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setSheetSet(sheetSet); | |
// Save the pdf file with PdfSaveOptions | |
wb.save("output.pdf", pdfSaveOptions); |