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 * “[file "root"] \xl \ printerSettings”. * Este documento explica cómo eliminar la configuración de impresora existente 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 te permite eliminar la configuración de impresora existente especificada para diferentes hojas en el archivo de Excel. El siguiente código de ejemplo ilustra cómo eliminar la configuración de impresora existente para todas las hojas de trabajo en el libro. Consulta su archivo de Excel de muestra, archivo de Excel de salida, salida de la consola y captura de pantalla como referencia.

Captura de pantalla

todo:image_alt_text

Código de muestra

//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
//Load source Excel file
Workbook wb = new Workbook(sourceDir + "sampleRemoveExistingPrinterSettingsOfWorksheets.xlsx");
//Get the sheet counts of the workbook
int sheetCount = wb.Worksheets.Count;
//Iterate all sheets
for (int i = 0; i < sheetCount; i++)
{
//Access the i-th worksheet
Worksheet ws = wb.Worksheets[i];
//Access worksheet page setup
PageSetup ps = ws.PageSetup;
//Check if printer settings for this worksheet exist
if (ps.PrinterSettings != null)
{
//Print the following message
Console.WriteLine("PrinterSettings of this worksheet exist.");
//Print sheet name and its paper size
Console.WriteLine("Sheet Name: " + ws.Name);
Console.WriteLine("Paper Size: " + ps.PaperSize);
//Remove the printer settings by setting them null
ps.PrinterSettings = null;
Console.WriteLine("Printer settings of this worksheet are now removed by setting it null.");
Console.WriteLine("");
}//if
}//for
//Save the workbook
wb.Save(outputDir + "outputRemoveExistingPrinterSettingsOfWorksheets.xlsx");

Salida de la consola

 PrinterSettings of this worksheet exist.

Sheet Name: Sheet1

Paper Size: PaperLegal

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

PrinterSettings of this worksheet exist.

Sheet Name: Sheet2

Paper Size: PaperEnvelopeB5

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

PrinterSettings of this worksheet exist.

Sheet Name: Sheet3

Paper Size: PaperA6

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

PrinterSettings of this worksheet exist.

Sheet Name: Sheet4

Paper Size: PaperA3

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