确定工作表的纸张大小是否为自动

可能的使用场景

大多数时候,工作表的纸张大小是自动的。自动时,常设置为信件.有时用户会根据他们的要求设置工作表的纸张大小。在这种情况下,纸张尺寸不是自动的。您可以使用工作表.getPageSetup().isAutomaticPaperSize()方法。

确定工作表的纸张大小是否为自动

下面给出的示例代码加载了以下两个 Excel 文件

并查看他们的第一个工作表的纸张大小是否是自动的。在 Microsoft Excel 中,您可以通过页面设置窗口检查纸张大小是否自动,如屏幕截图所示。

待办事项:图片_替代_文本

示例代码

// 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