Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The general protection options in Microsoft Excel are:
Protected worksheets don’t hide or protect sensitive data, so it’s different from file encryption. Generally, worksheet protection is suitable for presentation purposes. It prevents the end user from modifying data, content, and formatting in the worksheet.
Aspose.Cells for Python via .NET provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a worksheets collection that allows access to each worksheet in an Excel file. A worksheet is represented by the Worksheet class.
The Worksheet class provides the protect method that is used to apply protection on the worksheet. protect method accepts the following parameters:
The ProtectionType enumeration contains the following pre-defined protections types:
| Protection Types | Description |
|---|---|
| All | The user cannot modify anything on this worksheet |
| Contents | The user cannot enter data in this worksheet |
| Objects | The user cannot modify drawing objects |
| Scenarios | The user cannot modify saved scenarios |
| Structure | The user cannot modify the structure |
| Windows | Protection is applied to windows |
| None | No protection is applied |
The example below shows how to protect a worksheet with a password.
After the above code is used to protect the worksheet, you can check the protection on the worksheet by opening it. Once you open the file and try to add some data to the worksheet, you will see the following dialog:
| A dialog warning that a user can’t modify the worksheet |
|---|
![]() |
To work on the worksheet, unprotect the worksheet by selecting the Protection, then Unprotect Sheet from the Tools menu item.
After you select Unprotect Sheet menu item, a dialog will open that would prompt you to enter the password so that you may work on the worksheet as shown below:
|
|
There might be certain scenarios where you need to lock a few cells only in the worksheet. If you want to lock some specific cells in the worksheet, you have to unlock all the other cells in the worksheet. All the cells in a worksheet are already initialized for locking, you may check this opening any excel file into MS Excel and click the Format | Cells… to show Format Cells dialog box and then click the Protection tab and see a checkbox labeled “Locked” is checked by default.
The following points describe how to lock a few cells using MS Excel. This method applies to Microsoft Office Excel 97, 2000, 2002, 2003 and greater versions.
In this method, we use Aspose.Cells for Python via .NET API only to do the task.
Example: The following example exhibits how to protect a few cells in the worksheet. It unlocks all the cells in the worksheet first and then locks 3 cells (A1, B1, C1) in it. Finally, it protects the worksheet. The Style object contains a boolean property, is_locked. You can set is_locked property to true or false and apply Column/Row.ApplyStyle() method to lock or unlock the row/column with your desired attributes.
Aspose.Cells for Python via .NET allows you to easily lock any row in the worksheet. Here, we can make use of apply_style() method of Aspose.Cells.Row class to apply Style to a particular row in the worksheet. This method takes two arguments: a Style object and StyleFlag object which has all the members related to applied formatting.
The following example shows how to protect a row in the worksheet. It unlocks all the cells in the worksheet first and then locks the first row in it. Finally, it protects the worksheet. The Style object contains a boolean property, is_locked. You can set is_locked property to true or false to lock or unlock the row/column using the StyleFlag object.
Aspose.Cells for Python via .NET allows you to easily lock any column in the worksheet. Here, we can make use of apply_style() method of Aspose.Cells.Column class to apply Style to a particular column in the worksheet. This method takes two arguments: a Style object and StyleFlag object which has all the members related to applied formatting.
The following example shows how to protect a column in the worksheet. It unlocks all the cells in the worksheet first and then locks the first column in it. Finally, it protects the worksheet. The Style object contains a boolean property, is_locked. You can set is_locked property to true or false to lock or unlock the row/column using the StyleFlag object.
The following example shows how to allow users to edit a range in a protected worksheet.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.