Limitar el número de páginas generadas Conversión de Excel a PDF
Contents
[
Hide
]
A veces, deseas imprimir un rango de páginas en un archivo PDF de salida. Aspose.Cells tiene la capacidad de establecer un límite en cuántas páginas se generan al convertir una hoja de cálculo de Excel al formato de archivo PDF.
Limitar el número de páginas generadas
El siguiente ejemplo muestra cómo renderizar un rango de páginas (3 y 4) en un archivo de Microsoft Excel 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); | |
// Open an Excel file | |
Workbook wb = new Workbook(dataDir+ "TestBook.xlsx"); | |
// Instantiate the PdfSaveOption | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// Print only Page 3 and Page 4 in the output PDF | |
// Starting page index (0-based index) | |
options.PageIndex = 3; | |
// Number of pages to be printed | |
options.PageCount = 2; | |
// Save the PDF file | |
wb.Save(dataDir+ "outPDF1.out.pdf", options); |
Si la hoja de cálculo contiene fórmulas, es mejor llamar a Workbook.CalculateFormula() justo antes de renderizarla a PDF. Haciendo esto asegura que se recalculen los valores dependientes de la fórmula y que se rendericen correctamente en el archivo de salida.