menu

Document Processing

EditableRange Class - C# Word Library API Reference | Syncfusion

    Show / Hide Table of Contents

    EditableRange Class

    Represents an editable range in a Word document which enclosed between EditableRangeStart and EditableRangeEnd.

    Inheritance
    System.Object
    EditableRange
    Namespace: Syncfusion.DocIO.DLS
    Assembly: Syncfusion.DocIO.Base.dll
    Syntax
    public class EditableRange : Object

    Properties

    EditableRangeEnd

    Gets the editable range end. Read-only.

    Declaration
    public EditableRangeEnd EditableRangeEnd { get; }
    Property Value
    Type Description
    EditableRangeEnd

    The EditableRangeEnd that represents the end of the editable range.

    Examples

    The following example illustrates how to get an editable range from a Word document using its ID.

     
    // Create a new WordDocument instance and ensure it has minimal content. 
    WordDocument document = new WordDocument(); 
    document.EnsureMinimal(); 
    document.LastParagraph.AppendText(@"Adventure Works Cycles, the fictitious company on which the AdventureWorks ");  
    // Add an editable range to the paragraph. 
    EditableRangeStart rangeStart = document.LastParagraph.AppendEditableRangeStart(); 
    document.LastParagraph.AppendText(@"sample databases are based, is a large, multinational manufacturing company."); 
    EditableRangeEnd rangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart); 
    // Sets the protection with password and allows only reading. 
    document.Protect(ProtectionType.AllowOnlyReading, "password"); 
    // Save and close the document. 
    document.Save("EditableRange.docx", FormatType.Docx); 
    document.Close(); 
     
    ' Create a new WordDocument instance and ensure it has minimal content. 
    Dim document As New WordDocument() 
    document.EnsureMinimal() 
    document.LastParagraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ")  
    ' Add an editable range to the paragraph. 
    Dim rangeStart As EditableRangeStart = document.LastParagraph.AppendEditableRangeStart()
    document.LastParagraph.AppendText("sample databases are based, is a large, multinational manufacturing company.") 
    Dim rangeEnd As EditableRangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart) 
    ' Sets the protection with password and allows only reading. 
    document.Protect(ProtectionType.AllowOnlyReading, "password")  
    ' Save and close the document. 
    document.Save("EditableRange.docx", FormatType.Docx) 
    document.Close() 

    EditableRangeStart

    Gets the editable range start. Read-only.

    Declaration
    public EditableRangeStart EditableRangeStart { get; }
    Property Value
    Type Description
    EditableRangeStart

    The EditableRangeStart that represents the start of the editable range.

    Examples

    The following example illustrates how to get an editable range from a Word document using its ID.

     
    // Create a new WordDocument instance and ensure it has minimal content. 
    WordDocument document = new WordDocument(); 
    document.EnsureMinimal(); 
    document.LastParagraph.AppendText(@"Adventure Works Cycles, the fictitious company on which the AdventureWorks ");  
    // Add an editable range to the paragraph. 
    EditableRangeStart rangeStart = document.LastParagraph.AppendEditableRangeStart(); 
    // Retrieve the editable range ID. 
    string editableRangeId = rangeStart.Id; 
    document.LastParagraph.AppendText(@"sample databases are based, is a large, multinational manufacturing company."); 
    EditableRangeEnd rangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart); 
    // Sets the protection with password and allows only reading. 
    document.Protect(ProtectionType.AllowOnlyReading, "password"); 
    // Save and close the document. 
    document.Save("EditableRange.docx", FormatType.Docx); 
    document.Close(); 
     
    ' Create a new WordDocument instance and ensure it has minimal content. 
    Dim document As New WordDocument() 
    document.EnsureMinimal() 
    document.LastParagraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ")  
    ' Add an editable range to the paragraph. 
    Dim rangeStart As EditableRangeStart = document.LastParagraph.AppendEditableRangeStart()
    document.LastParagraph.AppendText("sample databases are based, is a large, multinational manufacturing company.") 
    ' Retrieve the editable range start ID. 
    Dim editableRangeId As String = rangeStart.Id 
    Dim rangeEnd As EditableRangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart) 
    ' Sets the protection with password and allows only reading. 
    document.Protect(ProtectionType.AllowOnlyReading, "password")  
    ' Save and close the document. 
    document.Save("EditableRange.docx", FormatType.Docx) 
    document.Close() 

    EditorGroup

    Gets or sets the editor group for editable range permission.

    Declaration
    public EditorType EditorGroup { get; set; }
    Property Value
    Type Description
    EditorType

    The EditorType member that specifies the type of editor group.

    Examples

    The following example illustrates how to set the EditorGroup for an editable range in a paragraph:

    // Create a new WordDocument instance and ensure it has minimal content.
    WordDocument document = new WordDocument();
    document.EnsureMinimal();
    document.LastParagraph.AppendText(@"Adventure Works Cycles, the fictitious company on which the AdventureWorks "); 
    // Add an editable range to the paragraph.
    EditableRangeStart rangeStart = document.LastParagraph.AppendEditableRangeStart();
    document.LastParagraph.AppendText(@"sample databases are based, is a large, multinational manufacturing company.");
    EditableRangeEnd rangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart);
    // Set the editor group.
    document.EditableRanges[0].EditorGroup = EditorType.Everyone; 
    // Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password");
    // Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx);
    document.Close();
    ' Create a new WordDocument instance and ensure it has minimal content.
    Dim document As New WordDocument()
    document.EnsureMinimal()
    document.LastParagraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ") 
    ' Add an editable range to the paragraph.
    Dim rangeStart As EditableRangeStart = document.LastParagraph.AppendEditableRangeStart()
    document.LastParagraph.AppendText("sample databases are based, is a large, multinational manufacturing company.")
    Dim rangeEnd As EditableRangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart) 
    ' Set the editor group.
    document.EditableRanges[0].EditorGroup = EditorType.Everyone 
    ' Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password") 
    ' Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx)
    document.Close()

    FirstColumn

    Gets or sets the column index where the editable range starts within the table. Default value is -1.

    Declaration
    public short FirstColumn { get; set; }
    Property Value
    Type
    System.Int16
    Remarks

    This property is valid for selecting table cells only when the corresponding editable range ends in the same row or in the following rows of the same table.

    This property defines the top-left corner cell of a rectangular selection region, as editable ranges in tables are restricted to rectangular areas.

    If the value is negative, greater than the number of cells in a row, or greater than the LastColumn value, the selection starts from the first cell of the respective row.

    Examples

    The following example demonstrates how to define an editable range that starts at a specific column in a table:

    // Create a word document and add a table
    WordDocument document = new WordDocument();
    document.AddSection();
    WTable table = document.LastSection.AddTable() as WTable;
    table.ResetCells(2, 3);
    // Add text and start the editable range at column 1
    table[0, 1].AddParagraph().AppendText("Editable content");
    EditableRangeStart rangeStart = table[0, 1].Paragraphs[0].AppendEditableRangeStart();
    // Add content inside the editable range
    table[1, 2].AddParagraph().AppendText("Editable Content");
    // End the editable range at column 2
    EditableRangeEnd rangeEnd = table[1, 2].Paragraphs[0].AppendEditableRangeEnd();
    document.EditableRanges[0].FirstColumn = 1;
    document.EditableRanges[0].LastColumn = 2;
    // Protect the document with read-only access
    document.Protect(ProtectionType.AllowOnlyReading, "password");
    // Save and close the document
    document.Save("EditableRange.docx", FormatType.Docx);
    document.Close();
    ' Create a word document and add a table
    Dim document As New WordDocument()
    document.AddSection()
    Dim table As WTable = TryCast(document.LastSection.AddTable(), WTable)
    table.ResetCells(2, 3)
    ' Add text and start the editable range at column 1
    table(0, 1).AddParagraph().AppendText("Editable content")
    Dim rangeStart As EditableRangeStart = table(0, 1).Paragraphs(0).AppendEditableRangeStart()
    ' Add content inside the editable range
    table(1, 2).AddParagraph().AppendText("Editable Content")
    ' End the editable range at column 2
    Dim rangeEnd As EditableRangeEnd = table(1, 2).Paragraphs(0).AppendEditableRangeEnd()
    document.EditableRanges[0].FirstColumn = 1
    document.EditableRanges[0].LastColumn = 2
    ' Protect the document with read-only access
    document.Protect(ProtectionType.AllowOnlyReading, "password")
    ' Save and close the document
    document.Save("EditableRange.docx", FormatType.Docx)
    document.Close()

    Id

    Gets the editable range id. Read-only.

    Declaration
    public string Id { get; }
    Property Value
    Type Description
    System.String

    A string that represents the editable range ID.

    Examples

    The following example illustrates how to get the ID of an editable range:

    // Create a new WordDocument instance and ensure it has minimal content.
    WordDocument document = new WordDocument();
    document.EnsureMinimal();
    document.LastParagraph.AppendText(@"Adventure Works Cycles, the fictitious company on which the AdventureWorks "); 
    // Add an editable range to the paragraph.
    EditableRangeStart rangeStart = document.LastParagraph.AppendEditableRangeStart();
    // Retrieve the editable range ID.
    string editableRangeId = rangeStart.Id;
    document.LastParagraph.AppendText(@"sample databases are based, is a large, multinational manufacturing company.");
    EditableRangeEnd rangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart);
    // Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password");
    // Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx);
    document.Close();
    ' Create a new WordDocument instance and ensure it has minimal content.
    Dim document As New WordDocument()
    document.EnsureMinimal()
    document.LastParagraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ") 
    ' Add an editable range to the paragraph.
    Dim rangeStart As EditableRangeStart = document.LastParagraph.AppendEditableRangeStart()
    document.LastParagraph.AppendText("sample databases are based, is a large, multinational manufacturing company.")
    ' Retrieve the editable range ID.
    Dim editableRangeId As String = rangeStart.Id
    Dim rangeEnd As EditableRangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart) 
    ' Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password") 
    ' Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx)
    document.Close()

    LastColumn

    Gets or sets the column index where the editable range ends within the table. Default value is -1.

    Declaration
    public short LastColumn { get; set; }
    Property Value
    Type
    System.Int16
    Remarks

    This property is applicable when selecting table cells using editable ranges. It defines the bottom-right corner cell of the rectangular selection region within the table.

    The corresponding editable range start must be in the same row or a row before the current one within the same table.

    If the value is negative, greater than the number of cells in a row, or less than the FirstColumn value, the range will automatically extend to the last cell of the respective row.

    Examples

    The following example demonstrates how to define an editable range that starts at a specific column in a table:

    // Create a word document and add a table
    WordDocument document = new WordDocument();
    document.AddSection();
    WTable table = document.LastSection.AddTable() as WTable;
    table.ResetCells(2, 3);
    // Add text and start the editable range at column 1
    table[0, 1].AddParagraph().AppendText("Editable content");
    EditableRangeStart rangeStart = table[0, 1].Paragraphs[0].AppendEditableRangeStart();
    // Add content inside the editable range
    table[1, 2].AddParagraph().AppendText("Editable Content");
    // End the editable range at column 2
    EditableRangeEnd rangeEnd = table[1, 2].Paragraphs[0].AppendEditableRangeEnd();
    document.EditableRanges[0].FirstColumn = 1;
    document.EditableRanges[0].LastColumn = 2;
    // Protect the document with read-only access
    document.Protect(ProtectionType.AllowOnlyReading, "password");
    // Save and close the document
    document.Save("EditableRange.docx", FormatType.Docx);
    document.Close();
    ' Create a word document and add a table
    Dim document As New WordDocument()
    document.AddSection()
    Dim table As WTable = TryCast(document.LastSection.AddTable(), WTable)
    table.ResetCells(2, 3)
    ' Add text and start the editable range at column 1
    table(0, 1).AddParagraph().AppendText("Editable content")
    Dim rangeStart As EditableRangeStart = table(0, 1).Paragraphs(0).AppendEditableRangeStart()
    ' Add content inside the editable range
    table(1, 2).AddParagraph().AppendText("Editable Content")
    ' End the editable range at column 2
    Dim rangeEnd As EditableRangeEnd = table(1, 2).Paragraphs(0).AppendEditableRangeEnd()
    document.EditableRanges[0].FirstColumn = 1
    document.EditableRanges[0].LastColumn = 2
    ' Protect the document with read-only access
    document.Protect(ProtectionType.AllowOnlyReading, "password")
    ' Save and close the document
    document.Save("EditableRange.docx", FormatType.Docx)
    document.Close()

    SingleUser

    Gets or sets the single user for editable range permission.

    Declaration
    public string SingleUser { get; set; }
    Property Value
    Type Description
    System.String

    A string that specifies the single user allowed to edit the range.

    Examples

    The following example illustrates how to set SingleUser for an editable range in a paragraph:

    // Create a new WordDocument instance and ensure it has minimal content.
    WordDocument document = new WordDocument();
    document.EnsureMinimal();
    document.LastParagraph.AppendText(@"Adventure Works Cycles, the fictitious company on which the AdventureWorks "); 
    // Add an editable range to the paragraph.
    EditableRangeStart rangeStart = document.LastParagraph.AppendEditableRangeStart();
    document.LastParagraph.AppendText(@"sample databases are based, is a large, multinational manufacturing company.");
    EditableRangeEnd rangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart);
     //Set the specific user.
    document.EditableRanges[0].SingleUser = "[email protected]"; 
    // Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password");
    // Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx);
    document.Close();
    ' Create a new WordDocument instance and ensure it has minimal content.
    Dim document As New WordDocument()
    document.EnsureMinimal()
    document.LastParagraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks ") 
    ' Add an editable range to the paragraph.
    Dim rangeStart As EditableRangeStart = document.LastParagraph.AppendEditableRangeStart()
    document.LastParagraph.AppendText("sample databases are based, is a large, multinational manufacturing company.")
    ' Set the specific user.
    document.EditableRanges[0].SingleUser = "[email protected]" 
    Dim rangeEnd As EditableRangeEnd = document.LastParagraph.AppendEditableRangeEnd(rangeStart) 
    ' Sets the protection with password and allows only reading.
    document.Protect(ProtectionType.AllowOnlyReading, "password") 
    ' Save and close the document.
    document.Save("EditableRange.docx", FormatType.Docx)
    document.Close()
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved