Eliminar Configuraciones de Impresora Existente de Hojas de Cálculo en Archivo Excel

Escenarios de uso posibles

A veces, los desarrolladores desean evitar que Excel incluya archivos .bin de la configuración de impresora en los archivos XLSX guardados. Los archivos de configuración de impresora se encuentran en “[archivo “raíz”]\xl\printerSettings”. Este documento explica cómo eliminar las configuraciones de impresora existentes utilizando las API de Aspose.Cells.

Eliminar la configuración existente de PrinterSettings de las hojas de cálculo en el archivo de Excel

Aspose.Cells le permite eliminar la configuración de impresión existente especificada para diferentes hojas en el archivo de Excel. El siguiente código de ejemplo ilustra cómo eliminar la configuración de impresión existente para todas las hojas de cálculo en el libro. Consulte su archivo de Excel de ejemplo, archivo de Excel de salida, salida de la consola y una captura de pantalla como referencia.

Captura de pantalla

todo:image_alt_text

Código de muestra

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load source Excel file
Workbook wb = new Workbook(srcDir + "sampleRemoveExistingPrinterSettingsOfWorksheets.xlsx");
//Get the sheet counts of the workbook
int sheetCount = wb.getWorksheets().getCount();
//Iterate all sheets
for(int i=0; i<sheetCount; i++)
{
//Access the i-th worksheet
Worksheet ws = wb.getWorksheets().get(i);
//Access worksheet page setup
PageSetup ps = ws.getPageSetup();
//Check if printer settings for this worksheet exist
if(ps.getPrinterSettings() != null)
{
//Print the following message
System.out.println("PrinterSettings of this worksheet exist.");
//Print sheet name and its paper size
System.out.println("Sheet Name: " + ws.getName());
System.out.println("Paper Size: " + ps.getPaperSize());
//Remove the printer settings by setting them null
ps.setPrinterSettings(null);
System.out.println("Printer settings of this worksheet are now removed by setting it null.");
System.out.println("");
}//if
}//for
//Save the workbook
wb.save(outDir + "outputRemoveExistingPrinterSettingsOfWorksheets.xlsx");

Salida de la consola

 PrinterSettings of this worksheet exist.

Sheet Name: Sheet1

Paper Size: 5

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet2

Paper Size: 34

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet3

Paper Size: 70

Printer settings of this worksheet are now removed by setting it null.

PrinterSettings of this worksheet exist.

Sheet Name: Sheet4

Paper Size: 8

Printer settings of this worksheet are now removed by setting it null.