إعدادات الصفحة وخيارات الطباعة

العمل مع إعدادات الصفحة والطباعة

لهذا المثال، أنشأنا سجل عمل في Microsoft Excel واستخدمنا Aspose.Cells لضبط إعدادات الصفحة وخيارات الطباعة.

استخدام Aspose.Cells لضبط خيارات إعداد الصفحة

ابدأ أولا بإنشاء ورقة عمل بسيطة في Microsoft Excel. ثم قم بتطبيق خيارات إعداد الصفحة عليها. سيقوم تنفيذ الكود بتغيير خيارات إعداد الصفحة كما هو موضح في صورة الشاشة أدناه.

ملف الإخراج.
todo:image_alt_text
  1. إنشاء ورقة عمل ببعض البيانات في Microsoft Excel:
    1. افتح برنامج Excel الجديد في Microsoft Excel.
    2. أضف بعض البيانات.
  2. ضبط خيارات إعداد الصفحة: قم بتطبيق خيارات إعداد الصفحة على الملف. وفيما يلي صورة للخيارات الافتراضية، قبل تطبيق الخيارات الجديدة.
خيارات إعداد الصفحة الافتراضية.
todo:image_alt_text
  1. قم بتنزيل وتثبيت Aspose.Cells:
    1. تنزيل Aspose.Cells for .Net.
    2. قم بتثبيته على كمبيوتر التطوير الخاص بك. جميع مكونات Aspose، عند التثبيت، تعمل في وضع التقييم. وضع التقييم لا يحتوي على حد زمني ويقوم فقط بحقن العلامات المائية إلى الوثائق المنتجة.
  2. أنشئ مشروعًا:
    1. ابدأ في Visual Studio. Net.
    2. أنشئ تطبيقًا جديدًا على الكونسول. سيظهر هذا المثال تطبيق وحدة تحكم C#، لكن يمكنك أيضًا استخدام VB.NET.
  3. أضف مراجع:
    1. يستخدم هذا المثال Aspose.Cells لذا أضف مرجعًا إلى تلك المكونة للمشروع. على سبيل المثال: …\Program Files\Aspose\Aspose.Cells\Bin\Net1.0\Aspose.Cells.dll
  4. اكتب التطبيق الذي يستدعي واجهة برمجة التطبيق:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open the template workbook
Workbook workbook = new Workbook(dataDir + "CustomerReport.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Setting the orientation to Portrait
worksheet.PageSetup.Orientation = PageOrientationType.Portrait;
// Setting the scaling factor to 100
// worksheet.PageSetup.Zoom = 100;
// OR Alternately you can use Fit to Page Options as under
// Setting the number of pages to which the length of the worksheet will be spanned
worksheet.PageSetup.FitToPagesTall = 1;
// Setting the number of pages to which the width of the worksheet will be spanned
worksheet.PageSetup.FitToPagesWide = 1;
// Setting the paper size to A4
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
// Setting the print quality of the worksheet to 1200 dpi
worksheet.PageSetup.PrintQuality = 1200;
//Setting the first page number of the worksheet pages
worksheet.PageSetup.FirstPageNumber = 2;
// Save the workbook
workbook.Save(dataDir + "PageSetup_out.xlsx");

ضبط خيارات الطباعة

إعدادات إعداد الصفحة توفر أيضًا العديد من خيارات الطباعة (المسمى أيضًا خيارات الورقة) التي تسمح للمستخدمين بالتحكم في كيفية طباعة صفحات ورق العمل. تسمح للمستخدمين ب:

  • تحديد منطقة طباعة معينة من ورقة عمل.
  • طباعة العناوين.
  • طباعة خطوط الشبكة.
  • طباعة عناوين الصفوف/الأعمدة.
  • تحقيق جودة مسودة.
  • طباعة التعليقات.
  • طباعة أخطاء الخلية.
  • تعريف ترتيب الصفحات.

المثال التالي يطبق خيارات الطباعة على الملف الذي تم إنشاؤه في المثال أعلاه (PageSetup.xls). يظهر اللقطة الشاشية أدناه الخيارات الافتراضية للطباعة قبل تطبيق الخيارات الجديدة.

مستند الإدخال
todo:image_alt_text
تغيير خيارات الطباعة ينفذ الشيفرة.
ملف الإخراج
todo:image_alt_text
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Open the template workbook
Workbook workbook = new Workbook(dataDir + "PageSetup.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
PageSetup pageSetup = worksheet.PageSetup;
// Specifying the cells range (from A1 cell to E30 cell) of the print area
pageSetup.PrintArea = "A1:E30";
// Defining column numbers A & E as title columns
pageSetup.PrintTitleColumns = "$A:$E";
// Defining row numbers 1 as title rows
pageSetup.PrintTitleRows = "$1:$2";
// Allowing to print gridlines
pageSetup.PrintGridlines = true;
// Allowing to print row/column headings
pageSetup.PrintHeadings = true;
// Allowing to print worksheet in black & white mode
pageSetup.BlackAndWhite = true;
// Allowing to print comments as displayed on worksheet
pageSetup.PrintComments = PrintCommentsType.PrintInPlace;
// Allowing to print worksheet with draft quality
pageSetup.PrintDraft = true;
// Allowing to print cell errors as N/A
pageSetup.PrintErrors = PrintErrorsType.PrintErrorsNA;
// Setting the printing order of the pages to over then down
pageSetup.Order = PrintOrderType.OverThenDown;
// Save the workbook
workbook.Save(dataDir + "PageSetup_Print_out.xlsx");