Verify Password Used to Protect the Worksheet

Contents
[ ]

The Protection.verify_password method returns true if the specified password matches the password used to protect the given worksheet and false if the specified password does not match. Following piece of code uses the Protection.verify_password method in conjunction with Protection.is_protected_with_password property to detect the password protection, and verifies the password.

from aspose.cells import 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(".")
# Create an instance of Workbook and load a spreadsheet
book = Workbook(dataDir + "Sample.xlsx")
# Access the protected Worksheet
sheet = book.worksheets[0]
# Check if Worksheet is password protected
if sheet.protection.is_protected_with_password:
# Verify the password used to protect the Worksheet
if sheet.protection.verify_password("1234"):
print("Specified password has matched")
else:
print("Specified password has not matched")