protect method

protect

Protects worksheet.

def protect(self, type):
    ...
ParameterTypeDescription
typeProtectionTypeProtection type.

Remarks

This method protects worksheet without password. It can protect worksheet in all versions of Excel file.

protect

Protects worksheet.

def protect(self, type, password, old_password):
    ...
ParameterTypeDescription
typeProtectionTypeProtection type.
passwordstrPassword.
old_passwordstrIf the worksheet is already protected by a password, please supply the old password.
Otherwise, you can set a null value or blank string to this parameter.

Remarks

This method can protect worksheet in all versions of Excel file.

Example

from aspose.cells import ProtectionType, Workbook

# Instantiating a Workbook object
excel = Workbook("template.xlsx")
# Accessing the first worksheet in the Excel file
worksheet = excel.worksheets[0]
# Protecting the worksheet with a password
worksheet.protect(ProtectionType.ALL, "aspose", None)
# Saving the modified Excel file in default (that is Excel 20003) format
excel.save("output.xls")

See Also