Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KB samples #205

Merged
merged 2 commits into from
Aug 5, 2024
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
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-using-regex-and-add-comments", "Find-text-using-regex-and-add-comments\Find-text-using-regex-and-add-comments.csproj", "{1D707C02-50C4-48CB-B034-FBB0D9C3CCE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.Build.0 = Release|Any CPU
{1D707C02-50C4-48CB-B034-FBB0D9C3CCE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D707C02-50C4-48CB-B034-FBB0D9C3CCE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D707C02-50C4-48CB-B034-FBB0D9C3CCE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D707C02-50C4-48CB-B034-FBB0D9C3CCE6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6140D05B-D8BA-4632-A04A-84100359C4AF}
SolutionGuid = {09759F9D-0056-4610-98CA-F6BBDC7F3FEE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Find_text_and_add_comments</RootNamespace>
<RootNamespace>Find_text_using_regex_and_add_comments</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.RegularExpressions;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.ReadWrite))
{
//Open the existing Word document.
using (WordDocument document = new WordDocument(fileStream, FormatType.Docx))
{
//Find all occurrence of a particular text ending with comma in the document using regex.
TextSelection[] textSelection = document.FindAll(new Regex("\\w+,"));
if (textSelection != null)
{
//Iterates through each occurrence and comment it.
for (int i = 0; i < textSelection.Count(); i++)
{
//Get the found text as a single text range.
WTextRange textRange = textSelection[i].GetAsOneRange();
//Get the owner paragraph of the found text.
WParagraph paragraph = textRange.OwnerParagraph;
//Get the index of the found text.
int textIndex = paragraph.ChildEntities.IndexOf(textRange);
//Add comment to a paragraph.
WComment comment = paragraph.AppendComment("comment test_" + i);
//Specify the author of the comment.
comment.Format.User = "Peter";
//Specify the initial of the author.
comment.Format.UserInitials = "St";
//Set the date and time for the comment.
comment.Format.DateTime = DateTime.Now;
//Insert the comment next to the textrange.
paragraph.ChildEntities.Insert(textIndex + 1, comment);
//Add the paragraph items to the commented items.
comment.AddCommentedItem(textRange);
}
}
//Create the file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Save the Word document to the file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"../../../Result.docx")) { UseShellExecute = true });

Loading