Unprotect a Worksheet
Contents
[
Hide
]
If a developer needs to remove protection from a protected worksheet at runtime so that some changes can be made to the file? This can easily be done with Aspose.Cells.
Unprotect a Worksheet
Using Microsoft Excel
To remove protection from a worksheet:
From the Tools menu, select Protection followed by Unprotect Sheet. Protection will be removed unless the worksheet is password protected. In this case, a dialog prompts for the password. Enter the password and worksheet will be unprotected then.
Unprotecting a Simply Protected Worksheet Using Aspose.Cells
A worksheet can be unprotected by calling the Worksheet class' Unprotect method. A simply protected worksheet is one which is not protected with a password. Such worksheets can be unprotected by calling the Unprotect method without passing a parameter.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unprotecting the worksheet without a password | |
worksheet.Unprotect(); | |
// Saving the Workbook | |
workbook.Save(dataDir + "output.xls", SaveFormat.Excel97To2003); |
Unprotecting a Password Protected Worksheet Using Aspose.Cells
A password protected worksheet is one that is protected with a password. Such worksheets can be unprotected by calling an overloaded version of the Unprotect method that takes the password as a parameter.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Unprotecting the worksheet with a password | |
worksheet.Unprotect(""); | |
// Save Workbook | |
workbook.Save(dataDir + "output.out.xls"); |