Supprimer les paramètres d imprimante existants des feuilles de calcul dans le fichier Excel

Scénarios d’utilisation possibles

Parfois, les développeurs veulent empêcher Excel d’inclure des fichiers de paramètres d’imprimante .bin dans les fichiers XLSX enregistrés. Les fichiers de paramètres d’imprimante se trouvent sous “[file “root”]\xl\printerSettings”. Ce document explique comment supprimer les paramètres d’imprimante existants en utilisant les APIs Aspose.Cells.

Supprimer les paramètres d’imprimante existants des feuilles de calcul dans le fichier Excel

Aspose.Cells vous permet de supprimer les paramètres d’imprimante existants spécifiés pour différentes feuilles du fichier Excel. Le code d’exemple suivant illustre comment supprimer les paramètres d’imprimante existants pour toutes les feuilles de calcul dans le classeur. Veuillez consulter son fichier Excel d’exemple, fichier Excel de sortie, la sortie de la console ainsi qu’une capture d’écran à titre de référence.

Capture d’écran

todo:image_alt_text

Code d’exemple

// 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");

Sortie console

 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.