验证用于保护工作表的密码
Contents
[
Hide
]
Aspose.Cells API增强了保护通过引入一些有用的属性和方法来类。一种这样的方法是[验证密码](https://reference.aspose.com/cells/java/com.aspose.cells/protection#verifyPassword(java.lang.String)允许将密码指定为 String 的实例,并验证是否已使用相同的密码来保护工作表。
验证用于保护工作表的密码
这[保护.verifyPassword](https://reference.aspose.com/cells/java/com.aspose.cells/protection#verifyPassword(java.lang.String) 方法返回真的如果指定的密码与用于保护给定工作表的密码匹配,错误的如果指定的密码不匹配。下面的一段代码使用了[保护.verifyPassword](https://reference.aspose.com/cells/java/com.aspose.cells/protection#verifyPassword(java.lang.String) 方法连同保护.isProtectedWithPassword属性检测密码保护,并验证密码。
This file contains hidden or 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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(VerifyPasswordtoProtectWorksheet.class); | |
// Create an instance of Workbook and load a spreadsheet | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Access the protected Worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Check if Worksheet is password protected | |
if (sheet.getProtection().isProtectedWithPassword()) { | |
// Verify the password used to protect the Worksheet | |
if (sheet.getProtection().verifyPassword("password")) { | |
System.out.println("Specified password has matched"); | |
} else { | |
System.out.println("Specified password has not matched"); | |
} | |
} |