Jede Arbeitsblatt in eine separate PDF Datei speichern
Contents
[
Hide
]
Aspose.Cells unterstützt die Konvertierung von XLS-Dateien (die Bilder, Diagramme usw. enthalten) in PDF-Dokumente. Aspose.Cells for .NET kann unabhängig voneinander arbeiten, um eine Tabelle in PDF zu konvertieren, und Sie müssen nicht Aspose.PDF für die Konvertierung verwenden. Für die Konvertierung sind keine temporären Dateien erforderlich, da der gesamte Vorgang im Speicher durchgeführt werden kann.
Jedes Arbeitsblatt in eine separate PDF-Datei speichern
Wenn Sie jedes Arbeitsblatt in Ihrer Vorlagen-Excel-Datei speichern möchten, um verschiedene PDF-Dateien zu generieren, können Sie dies einfach erreichen. Sie können versuchen, eine Blattindexierungsoption auf PdfSaveOptions.SheetSet festzulegen, um es einzeln in PDF zu rendern.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the Excel file path | |
string filePath = dataDir + "input.xlsx"; | |
// Instantiage a new workbook and open the Excel, File from its location | |
Workbook workbook = new Workbook(filePath); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.Worksheets.Count; | |
// Define PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Take Pdfs of each sheet | |
for (int j = 0; j < sheetCount; j++) | |
{ | |
Worksheet ws = workbook.Worksheets[j]; | |
//set worksheet to output | |
SheetSet sheetSet = new SheetSet(new int[] { ws.Index }); | |
pdfSaveOptions.SheetSet = sheetSet; | |
workbook.Save(dataDir + "worksheet-" + ws.Name + ".out.pdf", pdfSaveOptions); | |
} |
Wenn Ihre Tabelle Formeln enthält, ist es am besten, Workbook.CalculateFormula() kurz vor dem Rendern der Tabelle im PDF-Format aufzurufen. Auf diese Weise wird sichergestellt, dass die von Formeln abhängigen Werte neu berechnet und die richtigen Werte im PDF gerendert werden.