Protect and Unprotect Worksheet

Protect and unprotect Worksheet in MS Excel

protect and unprotect Worksheet

  1. Click Review > Protect Worksheet.
  2. Enter a password in the Password box.
  3. Select allow options.
  4. Select OK, re-enter the password to confirm it, and then select OK again.

Protect Worksheet Using Aspose.Cell for Python

Only need the following simple lines of code to implement protecting workbook structure of Excel files.

#Create a new file.
workbook = Workbook()
#Gets the first worksheet.
sheet = workbook.getWorksheets().get(0)
#Protect contents of the worksheet.
sheet.protect(ProtectionType.CONTENTS)
#Protect worksheet with password.
sheet.getProtection().setPassword('test')
#Save as Excel file.
workbook.save('Book1.xlsx')

Unprotect Worksheet Using Aspose.Cell for Python

Unprotecting worksheet is easy with Aspose.Cells API. If worksheet is password-protected, a correct password is required.

#Create a new file.
workbook = Workbook("Book1.xlsx")
#Gets the first worksheet.
sheet = workbook.getWorksheets().get(0)
#Protect contents of the worksheet.
sheet.unprotect("password")
#Save Excel file.
workbook.save("Book1.xlsx")