Get Paper Width and Height of Page Setup of Worksheet
Possible Usage Scenarios
Sometimes, you need to know the width and height of paper size as it has been set in page setup of the worksheet. Please use the PageSetup.PaperWidth and PageSetup.PaperHeight properties for this purpose.
Get Paper Width and Height of Page Setup of Worksheet
The following sample code explains the usage of PageSetup.PaperWidth and PageSetup.PaperHeight properties. It first changes the paper size to A2 and then finds the width and height of the paper, then it changes it to A3, A4, Letter and finds the width and height of paper respectively.
Sample Code
// 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); |
Console Output
Here is the console output of the above sample code.
PaperA2: 16.54x23.39
PaperA3: 11.69x16.54
PaperA4: 8.27x11.69
PaperLetter: 8.5x11