Skip to content

Commit aa77f4b

Browse files
committed
Added editable range sample
1 parent 016e0b2 commit aa77f4b

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-Editable-range-to-specific-paragraph", "Add-Editable-range-to-specific-paragraph\Add-Editable-range-to-specific-paragraph.csproj", "{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {48134F0E-F228-4631-90C5-02A0A3A5DD6B}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Add_Editable_range_to_specific_paragraph</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
namespace Add_Editable_range_to_specific_paragraph
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
// Load the Word document
11+
using (WordDocument document = new WordDocument(Path.GetFullPath("Data/Template.docx")))
12+
{
13+
// Access the first section of the document
14+
WSection section = document.Sections[0];
15+
// Insert an editable range at index 1 in the 2nd paragraph
16+
AddEditableRange(document, section.Paragraphs[1], 1);
17+
// Insert an editable range at index 2 in the 4th paragraph
18+
AddEditableRange(document, section.Paragraphs[3], 1);
19+
// Insert an editable range at index 4 in the 12th paragraph
20+
AddEditableRange(document, section.Paragraphs[11], 4);
21+
// Save the modified document to the new file
22+
document.Save(Path.GetFullPath(@"../../../Output/Result.docx"));
23+
}
24+
}
25+
/// <summary>
26+
/// Inserts an editable range at a specific index within a paragraph.
27+
/// </summary>
28+
/// <param name="document">The Word document instance</param>
29+
/// <param name="paragraph">The paragraph where the editable range will be inserted.</param>
30+
/// <param name="index">The index within the paragraph's child entities to insert the editable range.</param>
31+
private static void AddEditableRange(WordDocument document, WParagraph paragraph, int index)
32+
{
33+
// Create the start of the editable range
34+
EditableRangeStart editableRangeStart = new EditableRangeStart(document);
35+
// Insert the editable range start at the specified index in the paragraph
36+
paragraph.ChildEntities.Insert(index, editableRangeStart);
37+
// Set the editor group to allow everyone to edit this range
38+
editableRangeStart.EditorGroup = EditorType.Everyone;
39+
// Create the end of the editable range
40+
EditableRangeEnd editableRangeEnd = new EditableRangeEnd(document);
41+
// Insert the editable range end after the editable content
42+
paragraph.ChildEntities.Insert(index + 2, editableRangeEnd);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)