验证加密文件的密码
Contents
[
Hide
]
如果 Excel (xlsx、xlsb、xls、xlsm) 和 Open Office (ODS) 文件被锁定密码,Aspose 支持通过简单密码验证而无需解析文件的特定数据。
验证加密文件的密码
要验证加密文件的密码,Aspose.Cells for Python via .NET 提供了verify_password方法。这些方法接受两个参数,文件流和需要验证的密码。 以下代码片段演示了使用verify_password方法来验证提供的密码是否有效。
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
from aspose.cells import FileFormatUtil | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a Stream object | |
fstream = open(dataDir + "EncryptedBook1.xlsx", "rb") | |
isPasswordValid = FileFormatUtil.verify_password(fstream, "1234") | |
print("Password is Valid: " + str(isPasswordValid)) |