Skip to main content
.NET Framework 4.5.2+

Worksheet.ProtectedRanges Property

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

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v22.1.Core.dll


ProtectedRangeCollection ProtectedRanges { get; }

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.

Worksheet worksheet = workbook.Worksheets["ProtectionSample"];
workbook.Worksheets.ActiveWorksheet = worksheet;
worksheet["B2:J5"].Borders.SetOutsideBorders(Color.Red, BorderLineStyle.Thin);

// Specify user permission to edit a range in a protected worksheet.
ProtectedRange protectedRange = worksheet.ProtectedRanges.Add("My Range", worksheet["B2:J5"]);
EditRangePermission permission = new EditRangePermission();
permission.UserName = Environment.UserName;
permission.DomainName = Environment.UserDomainName;
permission.Deny = false;
protectedRange.SecurityDescriptor = protectedRange.CreateSecurityDescriptor(new EditRangePermission[] { permission });
// Protect a worksheet.
if (!worksheet.IsProtected)
    worksheet.Protect("password", WorksheetProtectionPermissions.Default);
// Add a note.
worksheet["B2"].Value = "This cell range is protected with a password. \n You cannot edit or format it until protection is removed." +
                        "\nTo remove protection, double-click the range and enter \"123\".";
worksheet.Visible = true;

The following code snippets (auto-collected from DevExpress Examples) contain references to the ProtectedRanges property.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also