Guardar Cada Hoja de Cálculo en un Archivo PDF Diferente
Contents
[
Hide
]
Aspose.Cells para Python via .NET admite la conversión de archivos XLS (que contienen imágenes, gráficos, etc.) a documentos PDF. Aspose.Cells para Python via .NET puede trabajar de forma independiente para convertir una hoja de cálculo a PDF y no es necesario usar Aspose.PDF para .NET para la conversión. La conversión no requiere que el software cree o use archivos temporales, ya que todo el proceso puede hacerse en memoria.
Guardar cada hoja de cálculo en un archivo PDF diferente
Si necesita guardar cada hoja de cálculo en su archivo de plantilla de Excel para generar archivos PDF diferentes, puede lograrlo fácilmente. Puede intentar configurar un índice de hoja a la vez con la opción PdfSaveOptions.sheet_set para renderizar a 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) |
Si su hoja de cálculo contiene fórmulas, es mejor llamar a Workbook.calculate_formula() justo antes de renderizar la hoja de cálculo en formato PDF. Al hacerlo, se asegurará de que los valores dependientes de las fórmulas se recalculen y los valores correctos se muestren en el PDF.