Guardar Cada Hoja de Cálculo en un Archivo PDF Diferente
Contents
[
Hide
]
Aspose.Cells admite la conversión de archivos XLS (que contienen imágenes, gráficos, etc.) a documentos PDF. Aspose.Cells for .NET puede trabajar de forma independiente para convertir una hoja de cálculo a PDF y no es necesario utilizar Aspose.PDF para .NET para la conversión. La conversión no requiere que el software cree o utilice archivos temporales, ya que todo el proceso se puede realizar en la 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.SheetSet 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
// 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); | |
} |
Si su hoja de cálculo contiene fórmulas, es mejor llamar a Workbook.CalculateFormula() 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.