Spara varje kalkylblad i en separat PDF fil
Contents
[
Hide
]
Aspose.Cells stöder konvertering av kalkylbladsfiler (som innehåller bilder, diagram osv.) till PDF-dokument. Aspose.Cells for Java kan fungera fristående för att konvertera en kalkylblad till PDF-dokument och du behöver inte längre använda Aspose.PDF för Java för konverteringen. Konverteringen kräver inte heller att skapa/använda temporära filer eftersom hela processen kan utföras i minnet.
Om du behöver spara varje kalkylblad i din mall Excel-fil för att generera olika PDF-filer kan detta enkelt uppnås. Du kan försöka ställa in ett kalkylbladindex på PdfSaveOptions.SheetSet-alternativet åt gången för att rendera till 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); | |
} |
Om kalkylbladet innehåller formler är det bäst att anropa metoden Workbook.calculateFormula() precis innan kalkylbladet renderas till PDF. Detta säkerställer att formelberoende värden beräknas om och de korrekta värdena renderas i PDF-filen.