验证加密文件的密码
Contents
[
Hide
]
如果Excel(xlsx、xlsb、xls、xlsm)和Open office(ODS)文件被密码锁定,Aspose.Cells for Java支持对文件进行简单密码验证,无需解析文件的特定数据。
验证加密文件的密码
要验证加密文件的密码,Aspose.Cells for Java提供了 VerifyPassword 方法。该方法接受两个参数,文件流和需要验证的密码。 以下代码片段演示了使用VerifyPassword方法来验证提供的密码是否有效。
示例代码
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(VerifyPassword.class) + "LoadingSavingConvertingAndManaging/"; | |
// Create a Stream object | |
FileInputStream fstream = new FileInputStream(dataDir + "EncryptedBook1.xlsx"); | |
boolean isPasswordValid = FileFormatUtil.verifyPassword(fstream, "1234"); | |
System.out.println("Password is Valid: " + isPasswordValid); |