使用 Aspose.Cells for Python via .NET 检查修改密码

在Microsoft Excel中检查修改密码

您可以在创建Microsoft Excel工作簿时指定打开密码修改密码。请参阅此截图,显示Microsoft Excel提供的界面以指定这些密码。

todo:image_alt_text

使用 Aspose.Cells for Python via .NET 检查修改密码

以下示例代码加载了源 Excel 文件。它具有打开密码为1234和修改密码为5678。该代码首先检查是否567为正确的修改密码,并返回false,然后检查是否5678为修改密码,并返回true。

from aspose.cells import LoadOptions, Workbook
# 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(".")
# Specify password to open inside the load options
opts = LoadOptions()
opts.password = "1234"
# Open the source Excel file with load options
workbook = Workbook(dataDir + "sampleBook.xlsx", opts)
# Check if 567 is Password to modify
ret = workbook.settings.write_protection.validate_password("567")
print("Is 567 correct Password to modify: " + str(ret))
# Check if 5679 is Password to modify
ret = workbook.settings.write_protection.validate_password("5678")
print("Is 5678 correct Password to modify: " + str(ret))

控制台输出

这是加载了源 Excel 文件后的上述示例代码的控制台输出。

Is 567 correct Password to modify: False

Is 5678 correct Password to modify: True