You can protect a worksheet with a password in order to prevent other users from accidentally or deliberately changing, moving, or deleting data. In Spread for WinForms, the Protect method provides a variety of password protection and lock options that are available in the Protect Sheet dialog box.
You can choose to protect or unprotect a worksheet using the Protect method which passes the WorksheetLocks enumeration as the parameter.
You can also set various types of protection options available for a worksheet using the IProtection interface. Each property from this interface gets a Boolean value, true or false indicating whether a particular action is allowed on a protected worksheet. For example, you can set the AllowDeletingColumns property as shown below:
In the above example, the MessageBox will show a false value as the worksheet has already been locked and protected to prevent column deletion.
You can implement the Protect method in the runtime UI by setting the tab strip as editable. This allows you to open the Protect Sheet dialog.
The following GIF illustrates opening protect sheet dialog box at runtime.
To access the Protect Sheet dialog, navigate to the Protect Sheet button in the Protect group under the Review tab of the Spread ribbon.
Select the multiple options you want to implement while protecting the worksheet from the Protect Sheet dialog box. Enter the password to protect the worksheet.
When you enter password to protect the worksheet, another dialog appears to confirm the password.
If the caps lock is on, a label indicator "CAPS LOCK ON" appears on the left side of the dialog box.
Once a password is successfully set, you can access the protected worksheet, but cannot make any changes to the sheet. To unprotect the worksheet enter the set password using the Unprotect Sheet dialog.
Currently worksheet protection options do not include protection of PivotTable, PivotChart, and Edit Scenarios, but still support import/export for those options. The worksheet protection options work only when LegacyBehaviors.Protect is not set, otherwise the old behavior is applied.