The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

Worksheet.Protect(String, WorksheetProtectionPermissions) Method

Protects worksheet elements to prevent them from being changed by the user.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

void Protect(
    string password,
    WorksheetProtectionPermissions permissions
)
Sub Protect(
    password As String,
    permissions As WorksheetProtectionPermissions
)
void Protect(
    string password,
    WorksheetProtectionPermissions permissions
)
Sub Protect(
    password As String,
    permissions As WorksheetProtectionPermissions
)
void Protect(
    string password,
    WorksheetProtectionPermissions permissions
)
Sub Protect(
    password As String,
    permissions As WorksheetProtectionPermissions
)

Parameters

Name Type Description
password String

A string that specifies a password for the worksheet. If the password is an empty string, the worksheet can be unprotected without using a password.

permissions WorksheetProtectionPermissions

A WorksheetProtectionPermissions enumeration that allows you to combine enumeration values to specify multiple worksheet elements to protect.

Parameters

Name Type Description
password String

A string that specifies a password for the worksheet. If the password is an empty string, the worksheet can be unprotected without using a password.

permissions WorksheetProtectionPermissions

A WorksheetProtectionPermissions enumeration that allows you to combine enumeration values to specify multiple worksheet elements to protect.

Parameters

Name Type Description
password String

A string that specifies a password for the worksheet. If the password is an empty string, the worksheet can be unprotected without using a password.

permissions WorksheetProtectionPermissions

A WorksheetProtectionPermissions enumeration that allows you to combine enumeration values to specify multiple worksheet elements to protect.

Remarks

If the worksheet is already protected, the Protect method throws an exception. Check the Worksheet.IsProtected property before calling the method.

Dim worksheet As Worksheet = workbook.Worksheets(0)

' Protect a worksheet. Prevent users from making changes to worksheet elements.
If Not worksheet.IsProtected Then
    worksheet.Protect("password", WorksheetProtectionPermissions.Default)
End If
workbook.BeginUpdate()
worksheet("C3:F8").Borders.SetOutsideBorders(Color.Red, BorderLineStyle.Thin)
worksheet("D5:E6").Merge()
worksheet("D5").Value = "Try to change me!"
worksheet("D5").Alignment.Vertical = SpreadsheetVerticalAlignment.Center
workbook.EndUpdate()

You can selectively unlock ranges in a protected worksheet. To do this, add a ProtectedRange to the Worksheet.ProtectedRanges collection. You can specify a password to edit the protected range with the ProtectedRange.SetPassword method and give specific users permission to edit the range with the ProtectedRange.CreateSecurityDescriptor method.

See Also