Version

Protect Method (Worksheet)

Protects the worksheet without a password.
Syntax

Parameters

allowDeletingColumns
Optional boolean indicating the new value for the AllowDeletingColumns.
allowDeletingRows
Optional boolean indicating the new value for the WorksheetProtection.AllowDeletingRows.
allowEditObjects
Optional boolean indicating the new value for the WorksheetProtection.AllowEditObjects.
allowEditScenarios
Optional boolean indicating the new value for the WorksheetProtection.AllowEditScenarios.
allowFiltering
Optional boolean indicating the new value for the WorksheetProtection.AllowFiltering.
allowFormattingCells
Optional boolean indicating the new value for the WorksheetProtection.AllowFormattingCells.
allowFormattingColumns
Optional boolean indicating the new value for the WorksheetProtection.AllowFormattingColumns.
allowFormattingRows
Optional boolean indicating the new value for the WorksheetProtection.AllowFormattingRows.
allowInsertingColumns
Optional boolean indicating the new value for the WorksheetProtection.AllowInsertingColumns.
allowInsertingHyperlinks
Optional boolean indicating the new value for the WorksheetProtection.AllowInsertingHyperlinks.
allowInsertingRows
Optional boolean indicating the new value for the WorksheetProtection.AllowInsertingRows.
allowSorting
Optional boolean indicating the new value for the WorksheetProtection.AllowSorting.
allowUsingPivotTables
Optional boolean indicating the new value for the WorksheetProtection.AllowUsingPivotTables.
Remarks

When a Worksheet is protected without a password, the end user may unprotect the Worksheet in Excel without having to supply a password. To programatically unprotect a Worksheet, one may use the Unprotect method.

The optional parameters are used to update the property values of the WorksheetProtection instance from this Worksheet's Protection property. If the parameter is null, the current value of the associated property will be retained; otherwise the property will be updated with the specified value. For example, if the AllowDeletingColumns is currently true and the allowDeletingColumns is null, then the property will continue to be true but if the allowDeletingColumns is false the AllowDeletingColumns will be changed to false.

When one protects a Worksheet in Excel, the UI allows one to choose which cells may be selected. To affect this state one would change the SelectionMode property before or after protecting the Worksheet.

Note: If IsProtected is already true, the method will be ignored.

Requirements

Target Platforms: Android 4.4+, iOS 8+

Development Environments: Visual Studio 2015+, Visual Studio for Mac Preview, Xamarin for Visual Studio 4.2+

See Also

Reference

Worksheet Class
Worksheet Members
HasProtectionPassword
IsProtected
Protection Property
WorksheetProtection Class
Unprotect()