检测工作表是否受密码保护

检测工作表是否受密码保护

Aspose.Cells for Java 8.7.0已公开了Protection.isProtectedWithPassword属性,用于检测工作表是否受密码保护。布尔类型Protection.isProtectedWithPassword字段返回true,如果Worksheet受到密码保护,返回false,如果没有。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectWorksheetisPasswordProtected.class);
// Create an instance of Workbook and load a spreadsheet
Workbook book = new Workbook(dataDir + "sample.xlsx");
// Access the protected Worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Check if Worksheet is password protected
if (sheet.getProtection().isProtectedWithPassword()) {
System.out.println("Worksheet is password protected");
}