Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36518.9 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA1949AA-B35C-4EB6-A763-7B9FAA8207FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {48134F0E-F228-4631-90C5-02A0A3A5DD6B}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_Editable_range_to_specific_paragraph</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;

namespace Add_Editable_range_to_specific_paragraph
{
class Program
{
static void Main(string[] args)
{
// Load the Word document
using (WordDocument document = new WordDocument(Path.GetFullPath("Data/Template.docx")))
{
// Access the first section of the document
WSection section = document.Sections[0];
// Insert an editable range at index 1 in the 2nd paragraph
AddEditableRange(document, section.Paragraphs[1], 1);
// Insert an editable range at index 2 in the 4th paragraph
AddEditableRange(document, section.Paragraphs[3], 1);
// Insert an editable range at index 4 in the 12th paragraph
AddEditableRange(document, section.Paragraphs[11], 4);
// Save the modified document to the new file
document.Save(Path.GetFullPath(@"../../../Output/Result.docx"));
}
}
/// <summary>
/// Inserts an editable range at a specific index within a paragraph.
/// </summary>
/// <param name="document">The Word document instance</param>
/// <param name="paragraph">The paragraph where the editable range will be inserted.</param>
/// <param name="index">The index within the paragraph's child entities to insert the editable range.</param>
private static void AddEditableRange(WordDocument document, WParagraph paragraph, int index)
{
// Create the start of the editable range
EditableRangeStart editableRangeStart = new EditableRangeStart(document);
// Insert the editable range start at the specified index in the paragraph
paragraph.ChildEntities.Insert(index, editableRangeStart);
// Set the editor group to allow everyone to edit this range
editableRangeStart.EditorGroup = EditorType.Everyone;
// Create the end of the editable range
EditableRangeEnd editableRangeEnd = new EditableRangeEnd(document);
// Insert the editable range end after the editable content
paragraph.ChildEntities.Insert(index + 2, editableRangeEnd);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36518.9 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-Text-and-Make-it-Editable", "Find-Text-and-Make-it-Editable\Find-Text-and-Make-it-Editable.csproj", "{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAA6F342-2A27-4644-8D7D-1AC2DDDEA5B3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CDAFC3B6-0F05-4FBC-8B77-214AF0CA9392}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Find_Text_and_Make_it_Editable</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Syncfusion.DocIO.DLS;

namespace Find_Text_and_Make_it_Editable
{
public class Program
{
public static void Main(string[] args)
{
//Loads template document
WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx"));
// Find all instances of the target text (text, case-insensitive, whole word match)
TextSelection[] textSelections = document.FindAll("Adventure Works Cycles", false, true);

// Append editable ranges around each matched text.
foreach (var selection in textSelections)
{
AppendEditableRange(selection);
}
// save and close the document
document.Save(Path.GetFullPath(Path.GetFullPath(@"../../../Output/Result.docx")));
document.Close();
}

public static void AppendEditableRange(TextSelection selection)
{
// Get the text range from the selection.
WTextRange[] textRanges = selection.GetRanges();
if (textRanges.Length > 0)
{
// Get the first and last text ranges in the selection.
WTextRange startTextRange = textRanges[0];
WTextRange endTextRange = textRanges[textRanges.Length - 1];
// Get the paragraph that owns the start text range.
WParagraph paragraph = startTextRange.OwnerParagraph;
// Create a new EditableRangeStart and assign it to everyone by default.
EditableRangeStart editableRangeStart = new EditableRangeStart(paragraph.Document);
editableRangeStart.EditorGroup = EditorType.Everyone;
// Find the index of the start text range within the paragraph's child entities.
int startTextRangeIndex = paragraph.ChildEntities.IndexOf(startTextRange);
// Insert the editable range start before the start text range.
paragraph.ChildEntities.Insert(startTextRangeIndex, editableRangeStart);
// Create a new EditableRangeEnd linked to the start.
EditableRangeEnd editableRangeEnd = new EditableRangeEnd(paragraph.Document, editableRangeStart);
// Find the index of the end text range and insert the editable range end after it.
int endTextRangeIndex = paragraph.ChildEntities.IndexOf(endTextRange);
paragraph.ChildEntities.Insert(endTextRangeIndex + 1, editableRangeEnd);
}
}
}
}
Loading