确定工作表的纸张尺寸是否为自动
Contents
[
Hide
]
可能的使用场景
大多数情况下,工作表的纸张尺寸是自动的。当它是自动时,通常设置为Letter。有时用户根据自己的要求设置工作表的纸张尺寸。在这种情况下,纸张尺寸不是自动的。您可以使用Worksheet.getPageSetup().isAutomaticPaperSize()方法找到工作表的纸张尺寸是否是自动的。
确定工作表的纸张大小是否自动
以下给出的示例代码加载以下两个Excel文件
并找到它们的第一个工作表的纸张尺寸是否为自动。在Microsoft Excel中,您可以通过页面设置窗口(如截图所示)检查纸张尺寸是否是自动的。
示例代码
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 | |
// 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()); |
控制台输出
以下是上述示例代码在给定的示例Excel文件上执行时的控制台输出。
First Worksheet of First Workbook - IsAutomaticPaperSize: false
First Worksheet of Second Workbook - IsAutomaticPaperSize: true