قم بإزالة إعدادات PrinterSettings الموجودة من أوراق العمل في ملف Excel
Contents
[
Hide
]
سيناريوهات الاستخدام الممكنة
يريد المطورون أحيانًا منع Excel من تضمين ملفات*.سلة مهملات* ملفات إعدادات الطابعة في ملفات XLSX المحفوظة. توجد ملفات إعدادات الطابعة أسفل*"[ملف" جذر “] \ xl \ إعدادات الطابعة”.* يشرح هذا المستند كيفية إزالة إعدادات الطابعة الحالية باستخدام Aspose.Cells APIs.
قم بإزالة إعدادات PrinterSettings الموجودة من أوراق العمل في ملف 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
//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"); |
إخراج وحدة التحكم
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.