ProtectedRangeCollection.Add

ProtectedRangeCollection.Add method

Adds a ProtectedRange item to the collection.

public int Add(string name, int startRow, int startColumn, int endRow, int endColumn)
ParameterTypeDescription
nameStringRange title. This is used as a descriptor, not as a named range definition.
startRowInt32Start row index of the range.
startColumnInt32Start column index of the range.
endRowInt32End row index of the range.
endColumnInt32End column index of the range.

Return Value

object index.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class ProtectedRangeCollectionMethodAddWithStringInt32Int32Int32Int32Demo
    {
        public static void Run()
        {
            Workbook workbook = new Workbook();
            ProtectedRangeCollection pranges = workbook.Worksheets[0].AllowEditRanges;
            
            // Add protected range with name and coordinates
            int index = pranges.Add("Range1", 0, 0, 10, 10);
            
            // Access the added range
            ProtectedRange range = pranges[index];
            
            // Set security descriptor
            string securityDescriptor = "O:WDG:WDD:(D;;CC;;;S-1-5-21-2854911246-2539335229-2923752399-1000)(A;;CC;;;S-1-5-21-2854911246-2539335229-2923752399-1013)";
            range.SecurityDescriptor = securityDescriptor;
            
            // Save and verify
            workbook.Save("output.xlsx");
        }
    }
}

See Also