الحصول على عرض وارتفاع الورقة من تهيئة الصفحة لورقة العمل
سيناريوهات الاستخدام المحتملة
في بعض الأحيان، قد تحتاج إلى معرفة عرض وارتفاع حجم الورقة كما تم تعيينه في تهيئة الصفحة لورقة العمل. يرجى استخدام الخصائص ( PageSetup.PaperWidth ) و( PageSetup.PaperHeight ) لهذا الغرض.
الحصول على عرض وارتفاع الورقة من تهيئة الصفحة لورقة العمل
الشيفرة المصدرية التالية تشرح استخدام الخصائص PageSetup.PaperWidth و PageSetup.PaperHeight. تقوم أولاً بتغيير حجم الورق إلى A2 ثم تجد عرض وارتفاع الورق، ثم تقوم بتغييره إلى A3، A4، رسالة وتجد عرض وارتفاع الورق على التوالي.
الكود المثالي
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Create workbook | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Set paper size to A2 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_2); | |
System.out.println("PaperA2: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to A3 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_3); | |
System.out.println("PaperA3: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to A4 and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4); | |
System.out.println("PaperA4: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); | |
//Set paper size to Letter and print paper width and height in inches | |
ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_LETTER); | |
System.out.println("PaperLetter: " + ws.getPageSetup().getPaperWidth() + "x" + ws.getPageSetup().getPaperHeight()); |
مخرجات الوحدة
فيما يلي مخرجات وحدة الإدخال الخاصة بالكود المصدري أعلاه.
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11.0