.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

Worksheet.ProtectedRanges Property

Provides access to a collection of protected ranges in a current worksheet.

Namespace: DevExpress.Spreadsheet

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


ProtectedRangeCollection ProtectedRanges { get; }
ReadOnly Property ProtectedRanges As ProtectedRangeCollection

Property Value

Type Description

A ProtectedRangeCollection object containing all protected ranges of the worksheet.


The ProtectedRanges provides access to a collection of ranges or cells which are locked in a protected worksheet.

The entire worksheet is protected with a "password" password. End-users can only select cells.

On an attempt to edit range "C3:E8" on a protected sheet, the end-user will be prompted for a password ("123") unless the application which loaded the worksheet is not run under the same account as the application which has executed the following code snippet. If it is so, a password is not required to edit the range "C3:E8".

Dim worksheet As Worksheet = workbook.Worksheets(0)
worksheet("C3:E8").Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin)

' Give specific user permission to edit a range in a protected worksheet. 
Dim protectedRange As ProtectedRange = worksheet.ProtectedRanges.Add("My Range", worksheet("C3:E8"))
Dim permission As New EditRangePermission()
permission.UserName = Environment.UserName
permission.DomainName = Environment.UserDomainName
permission.Deny = False
protectedRange.SecurityDescriptor = protectedRange.CreateSecurityDescriptor(New EditRangePermission() { permission })

' Protect a worksheet.
If Not worksheet.IsProtected Then
    worksheet.Protect("password", WorksheetProtectionPermissions.Default)
End If

worksheet.ActiveView.ShowGridlines = False
See Also