保护和取消保护工作表

在 MS Excel 中保护和取消保护工作表

保护和取消保护工作表

  1. 点击 审阅 > 保护工作表
  2. 密码框 中输入密码。
  3. 选择 允许 选项。
  4. 选择 确定,重新输入密码以确认,然后再次选择 确定

使用Aspose.Cell for Python保护工作表

只需要以下简单代码行来实现保护 Excel 文件的工作簿结构。

#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')

使用Aspose.Cell for Python取消保护工作表

使用 Aspose.Cells API 轻松取消工作表保护。如果工作表受密码保护,需要正确的密码。

#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")