Salva ciascun foglio di calcolo in un file PDF separato
Contents
[
Hide
]
Aspose.Cells for Python via .NET supporta la conversione di file XLS (che contengono immagini, grafici, ecc.) in documenti PDF. Aspose.Cells for Python via .NET può lavorare indipendentemente 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 file temporanei poiché l’intero processo può essere eseguito in memoria.
Salva ciascun foglio di calcolo in un file PDF separato
Se è necessario salvare ciascun foglio di lavoro nel file di modello Excel per generare file PDF diversi, è possibile farlo facilmente. È possibile provare a impostare un indice di foglio alla volta sull’opzione PdfSaveOptions.sheet_set per renderlo 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
from aspose.cells import PdfSaveOptions, Workbook | |
from aspose.cells.rendering import SheetSet | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Get the Excel file path | |
filePath = dataDir + "input.xlsx" | |
# Instantiage a new workbook and open the Excel, File from its location | |
workbook = Workbook(filePath) | |
# Get the count of the worksheets in the workbook | |
sheetCount = len(workbook.worksheets) | |
# Define PdfSaveOptions | |
pdfSaveOptions = PdfSaveOptions() | |
# Take Pdfs of each sheet | |
for j in range(sheetCount): | |
ws = workbook.worksheets[j] | |
# set worksheet to output | |
sheetSet = SheetSet([ws.index]) | |
pdfSaveOptions.sheet_set = sheetSet | |
workbook.save(dataDir + "worksheet-" + ws.name + ".out.pdf", pdfSaveOptions) |
Se il foglio di calcolo contiene formule, è meglio chiamare Workbook.calculate_formula() proprio prima di rendere il foglio di calcolo in formato PDF. In questo modo si garantisce il ricalcolo dei valori dipendenti dalle formule e la visualizzazione dei valori corretti nel PDF.