Unprotect a Worksheet
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.
// 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.
// 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"); |