删除Excel文件中工作表的现有打印设置
Contents
[
Hide
]
可能的使用场景
有时开发人员希望防止Excel在保存的XLSX文件中包含打印设置的*.bin*文件。打印设置文件位于“[file “root”]\xl\printerSettings”下。本文档介绍了如何使用Aspose.Cells API删除现有的打印设置。
删除Excel文件中工作表的现有打印设置
Aspose.Cells允许您删除Excel文件中不同工作表指定的现有打印设置。以下示例代码说明了如何删除工作簿中所有工作表的现有打印设置。请参阅其示例Excel文件、输出Excel文件、控制台输出以及参考的屏幕截图。
屏幕截图
示例代码
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-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"); |
控制台输出
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.