获取工作表页面设置的纸张宽度和高度
Contents
[
Hide
]
可能的使用场景
有时,您需要知道页面设置中纸张大小的宽度和高度。请为此目的使用PageSetup.PaperWidth和PageSetup.PaperHeight属性。
获取工作表页面设置的纸张宽度和高度
以下示例代码解释了PageSetup.PaperWidth和PageSetup.PaperHeight属性的用法。它首先将纸张大小更改为A2,然后找到纸张的宽度和高度,然后将其更改为A3,A4,Letter,并分别找到纸张的宽度和高度。
示例代码
This file contains hidden or 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-.NET | |
// Create an instance of Workbook class | |
Workbook book = new Workbook(); | |
// Access first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Set paper size to A2 and print paper width and height in inches | |
sheet.PageSetup.PaperSize = PaperSizeType.PaperA2; | |
Console.WriteLine("PaperA2: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight); | |
// Set paper size to A3 and print paper width and height in inches | |
sheet.PageSetup.PaperSize = PaperSizeType.PaperA3; | |
Console.WriteLine("PaperA3: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight); | |
// Set paper size to A4 and print paper width and height in inches | |
sheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
Console.WriteLine("PaperA4: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight); | |
// Set paper size to Letter and print paper width and height in inches | |
sheet.PageSetup.PaperSize = PaperSizeType.PaperLetter; | |
Console.WriteLine("PaperLetter: " + sheet.PageSetup.PaperWidth + "x" + sheet.PageSetup.PaperHeight); |
控制台输出
这是上面示例代码的控制台输出。
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11