Determine if Paper Size of Worksheet is Automatic
Possible Usage Scenarios
Most of the time, the paper size of the worksheet is automatic. When it is automatic, it is often set as Letter. Sometimes the user sets the paper size of the worksheet as per their requirements. In this case, the paper size is not automatic. You can find if the worksheet paper size is automatic or not using the Worksheet.getPageSetup().isAutomaticPaperSize() method.
Determine if Paper Size of Worksheet is Automatic
The sample code given below loads the following two Excel files
and find if the paper size of their first worksheet is automatic or not. In Microsoft Excel, you can check if the paper size is automatic or not via the Page Setup window as shown in this screenshot.
Sample Code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Load the first workbook having automatic paper size false | |
Workbook wb1 = new Workbook(srcDir + "samplePageSetupIsAutomaticPaperSize-False.xlsx"); | |
// Load the second workbook having automatic paper size true | |
Workbook wb2 = new Workbook(srcDir + "samplePageSetupIsAutomaticPaperSize-True.xlsx"); | |
// Access first worksheet of both workbooks | |
Worksheet ws11 = wb1.getWorksheets().get(0); | |
Worksheet ws12 = wb2.getWorksheets().get(0); | |
// Print the PageSetup.IsAutomaticPaperSize property of both worksheets | |
System.out.println("First Worksheet of First Workbook - IsAutomaticPaperSize: " + ws11.getPageSetup().isAutomaticPaperSize()); | |
System.out.println("First Worksheet of Second Workbook - IsAutomaticPaperSize: " + ws12.getPageSetup().isAutomaticPaperSize()); |
Console Output
Here is the console output of the above sample code when executed with the given sample Excel files.
First Worksheet of First Workbook - IsAutomaticPaperSize: false
First Worksheet of Second Workbook - IsAutomaticPaperSize: true