Protect and Unprotect Worksheet
Contents
[
Hide
]
To prevent other users from accidentally or deliberately changing, moving, or deleting data in a worksheet, you can lock the cells on your Excel worksheet and then protect the sheet with a password.
Protect and unprotect Worksheet in MS Excel
- Click Review > Protect Worksheet.
- Enter a password in the Password box.
- Select allow options.
- Select OK, re-enter the password to confirm it, and then select OK again.
Protect Worksheet Using Aspose.Cell for .Net
Only need the following simple lines of code to implement protecting workbook structure of Excel files.
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 = new Workbook(); | |
//Gets the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
//Protect contents of the worksheet. | |
sheet.Protect(ProtectionType.Contents); | |
//Protect worksheet with password. | |
sheet.Protection.Password = "test"; | |
//Save as Excel file. | |
workbook.Save("Book1.xlsx"); |
Unprotect Worksheet Using Aspose.Cell for .Net
Unprotecting worksheet is easy with Aspose.Cells API. If worksheet is password-protected, a correct password is required.
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 = new Workbook("Book1.xlsx"); | |
//Gets the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
//Protect contents of the worksheet. | |
sheet.Unprotect("password"); | |
//Save Excel file. | |
workbook.Save("Book1.xlsx"); |