Salva ciascun foglio di calcolo in un file PDF separato
Contents
[
Hide
]
Aspose.Cells supporta la conversione di file di fogli elettronici (che contengono immagini, grafici, ecc.) in documenti PDF. Aspose.Cells for Java può lavorare in modo indipendente per convertire un foglio di calcolo in un documento PDF e non è più necessario utilizzare Aspose.PDF for Java per la conversione. La conversione non richiede di creare / utilizzare file temporanei in quanto l’intero processo può essere eseguito in memoria.
Se hai bisogno di salvare ogni foglio di lavoro nel tuo file di Excel modello per generare file PDF diversi. Ciò può essere facilmente raggiunto. Puoi provare a impostare un’opzione di indice del foglio a PdfSaveOptions.SheetSet alla volta per renderla in 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(SaveEachWorksheettoDifferentPDF.class); | |
// Instantiate a new workbook and open the Excel | |
// File from its location | |
Workbook workbook = new Workbook(dataDir + "input.xlsx"); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.getWorksheets().getCount(); | |
// Define PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Take Pdfs of each sheet | |
for (int j = 0; j < sheetCount; j++) { | |
Worksheet ws = workbook.getWorksheets().get(j); | |
//set worksheet to output | |
SheetSet sheetSet = new SheetSet(new int[] { ws.getIndex() }); | |
pdfSaveOptions.setSheetSet(sheetSet); | |
workbook.save(dataDir + "_" + ws.getName() + ".pdf", pdfSaveOptions); | |
} |
Se il foglio di calcolo contiene formule, è meglio chiamare il metodo Workbook.calculateFormula() proprio prima di renderizzare il foglio di calcolo in PDF. Ciò garantisce che i valori dipendenti dalla formula vengano ricalcolati e i valori corretti vengano resi in PDF.