Skip to content

Commit 3cb49d3

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
Comments
1 parent 7779e83 commit 3cb49d3

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-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.10.34928.147
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-and-add-comments", "Find-text-and-add-comments\Find-text-and-add-comments.csproj", "{8B2E34B8-B23D-4717-A86A-34EB32012EC3}"
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+
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.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 = {6140D05B-D8BA-4632-A04A-84100359C4AF}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Find_text_and_add_comments</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+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
using (FileStream inputStream = new FileStream(@"../../../Data/InsertComment.docx", FileMode.Open, FileAccess.Read))
5+
{
6+
//Open the existing Word document.
7+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
8+
{
9+
//Find all occurrence of a particular text ending with comma in the document using regex.
10+
TextSelection[] textSelection = document.FindAll("panda", true, true);
11+
if (textSelection != null)
12+
{
13+
//Iterates through each occurrence and comment it.
14+
for (int i = 0; i < textSelection.Count(); i++)
15+
{
16+
WTextRange textRange = textSelection[i].GetAsOneRange();
17+
18+
//Get the index of the found text.
19+
int textIndex = textRange.OwnerParagraph.ChildEntities.IndexOf(textRange);
20+
//Add comment to a paragraph.
21+
WComment comment = textRange.OwnerParagraph.AppendComment("comment test_" + i);
22+
//Specify the author of the comment.
23+
comment.Format.User = "Peter";
24+
//Set the date and time for the comment.
25+
comment.Format.DateTime = DateTime.Now;
26+
//Insert the comment next to the textrange.
27+
textRange.OwnerParagraph.ChildEntities.Insert(textIndex + 1, comment);
28+
//Add the paragraph items to the commented items.
29+
comment.AddCommentedItem(textRange);
30+
}
31+
}
32+
33+
//Save the Word document
34+
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
35+
{
36+
document.Save(outputStream, FormatType.Docx);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)