Salva i fogli di lavoro specificati in PDF
Per impostazione predefinita, Aspose.Cells salva tutti i fogli di lavoro visibili in un libro di lavoro in un file pdf. Con PdfSaveOptions.SheetSet opzione, è possibile salvare i fogli di lavoro specificati in un file pdf. ad es. è possibile salvare il foglio di lavoro attivo in pdf, salvare tutti i fogli di lavoro (sia visibili che nascosti) in pdf, salvare più fogli di lavoro personalizzati in pdf.
Salva il foglio di lavoro attivo in PDF
Se si desidera esportare solo il foglio attivo in pdf, è possibile farlo passando SheetSet.Active all’opzione PdfSaveOptions.SheetSet.
Il foglio Sheet2
è il foglio attivo del file di origine 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); |
Salva tutti i fogli di lavoro in PDF
SheetSet.Visible indica le fogli visibili in un libro di lavoro, e SheetSet.All indica tutti i fogli, inclusi sia quelli visibili che quelli nascosti/invisibili in un libro di lavoro. Se si desidera esportare tutti i fogli in PDF, è sufficiente passare l’opzione SheetSet.All a PdfSaveOptions.SheetSet.
Il file di origine sheetset-example.xlsx contiene tutti e quattro i fogli con il foglio nascosto 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); |
Salva fogli specificati in PDF
Se si desidera esportare più fogli desiderati/personalizzati in PDF, è possibile farlo passando gli indici di più fogli all’opzione 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); |