从工作表的页面设置获取纸张的宽度和高度
Contents
[
Hide
]
可能的使用场景
有时,您需要知道工作表页面设置中设置的纸张尺寸的宽度和高度。为此,请使用PageSetup.PaperWidth和PageSetup.PaperHeight属性。
从工作表的页面设置获取纸张的宽度和高度
以下示例代码解释了PageSetup.PaperWidth和PageSetup.PaperHeight属性的用法。首先将纸张大小更改为A2,然后找到纸张的宽度和高度,然后将其更改为A3、A4、Letter,并依次找到纸张的宽度和高度。
示例代码
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 | |
//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