保护和取消保护工作表
Contents
[
Hide
]
为防止其他用户意外或故意更改、移动或删除工作表中的数据,您可以锁定 Excel 工作表上的单元格,然后使用密码保护工作表。
在 MS Excel 中保护和取消保护工作表
- 点击查看 > 保护工作表.
- 输入密码密码框.
- 选择允许选项。
- 选择好的 重新输入密码进行确认,然后选择好的再次。
使用 Aspose.Cell for Python 保护工作表
只需要下面几行简单的代码就可以实现对Excel文件工作簿结构的保护。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 可以轻松取消保护工作表。如果工作表受密码保护,则需要正确的密码。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |