保护和取消保护工作表
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") |