diff --git a/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color.sln b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color.sln new file mode 100644 index 000000000..2087792cd --- /dev/null +++ b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36717.8 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-by-highlight-color", "Find-text-by-highlight-color\Find-text-by-highlight-color.csproj", "{29506EA3-6180-4345-BB19-EAC37D937CBF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {29506EA3-6180-4345-BB19-EAC37D937CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {29506EA3-6180-4345-BB19-EAC37D937CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {29506EA3-6180-4345-BB19-EAC37D937CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {29506EA3-6180-4345-BB19-EAC37D937CBF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CCA30F13-0EBD-4B5C-997C-689163ECE8BC} + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Data/Input.docx b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Data/Input.docx new file mode 100644 index 000000000..d4136c78b Binary files /dev/null and b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Data/Input.docx differ diff --git a/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Find-text-by-highlight-color.csproj b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Find-text-by-highlight-color.csproj new file mode 100644 index 000000000..c166ecdef --- /dev/null +++ b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Find-text-by-highlight-color.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Find_text_by_highlight_color + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Output/.gitkeep b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Program.cs b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Program.cs new file mode 100644 index 000000000..f14a7ac15 --- /dev/null +++ b/Paragraphs/Find-highlight-text/.NET/Find-text-by-highlight-color/Program.cs @@ -0,0 +1,47 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +namespace Find_an_text_by_highlight_color +{ + class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Creates a new Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic)) + { + // Find all text ranges in the document where the highlight color is Yellow + List textRanges = document.FindAllItemsByProperty(EntityType.TextRange, "CharacterFormat.HighlightColor.Name", "Yellow"); + // Check if any matching text ranges were found + if (textRanges != null) + { + // Create or overwrite the text file + using (StreamWriter writer = new StreamWriter(Path.GetFullPath(@"Output/result.txt"), false)) + { + if (textRanges != null) + { + //Iterate and write the highlight color name of the current text range to the file + foreach (Entity entity in textRanges) + { + WTextRange textRange = entity as WTextRange; + writer.WriteLine($"HighlightColor: {textRange.CharacterFormat.HighlightColor.Name}"); + writer.WriteLine($"Text: {textRange.Text}"); + writer.WriteLine(); // Blank line between entries + } + } + else + { + // If no highlighted text ranges were found, write a message to the file + writer.WriteLine("No text ranges with highlight were found."); + } + } + } + } + } + } + + } +} +