Rimuovi le impostazioni della stampante esistenti dei fogli di lavoro nel file Excel
Possibili Scenari di Utilizzo
A volte gli sviluppatori vogliono impedire ad Excel di includere i file .bin delle impostazioni della stampante nei file XLSX salvati. I file delle impostazioni della stampante si trovano in "[file “root”]\xl\printerSettings". Questo documento spiega come rimuovere le impostazioni della stampante esistenti utilizzando le API di Aspose.Cells.
Rimuovi le impostazioni della stampante esistenti dei fogli di lavoro nel file Excel
Aspose.Cells consente di rimuovere le impostazioni della stampante esistenti specificate per fogli diversi nel file Excel. Il seguente codice di esempio illustra come rimuovere le impostazioni della stampante esistenti per tutti i fogli di lavoro nella cartella di lavoro. Si prega di consultare il file Excel di esempio, file Excel di output, output della console e la schermata per un riferimento.
Screenshot
Codice di Esempio
//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"); |
Output della console
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.