Salva ogni foglio di lavoro in un file PDF diverso
Contents
[
Hide
]
Aspose.Cells supporta la conversione di file XLS (che contengono immagini, grafici, ecc.) in documenti PDF. Aspose.Cells for .NET può funzionare in modo indipendente per convertire un foglio di calcolo in PDF e non è necessario utilizzare Aspose.PDF for .NET per la conversione. La conversione non richiede al software di creare o utilizzare alcun file temporaneo poiché l’intero processo può essere eseguito in memoria.
Salva ogni foglio di lavoro in un file PDF diverso
Se è necessario salvare ogni foglio di lavoro nel file Excel del modello per generare diversi file PDF, è possibile farlo facilmente. Puoi provare a nascondere i fogli nel file e rendere visibile un foglio alla volta per eseguire il rendering su 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-.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); | |
} |
Se il tuo foglio di calcolo contiene formule, è meglio chiamareWorkbook.CalculateFormula()appena prima di eseguire il rendering del foglio di calcolo nel formato PDF. In questo modo si assicurerà che i valori dipendenti dalla formula vengano ricalcolati e che i valori corretti vengano visualizzati in PDF.