Skip to content

Commit f9b0b3c

Browse files
ES-992091- Sample added
1 parent 859e6bf commit f9b0b3c

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-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.36717.8 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
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}"
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+
{29506EA3-6180-4345-BB19-EAC37D937CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{29506EA3-6180-4345-BB19-EAC37D937CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{29506EA3-6180-4345-BB19-EAC37D937CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{29506EA3-6180-4345-BB19-EAC37D937CBF}.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 = {CCA30F13-0EBD-4B5C-997C-689163ECE8BC}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 24 additions & 0 deletions
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>Find_text_by_highlight_color</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\Input.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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Find_an_text_by_highlight_color
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
11+
{
12+
//Creates a new Word document.
13+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
14+
{
15+
// Find all text ranges in the document where the highlight color is Yellow
16+
List<Entity> textRanges = document.FindAllItemsByProperty(EntityType.TextRange, "CharacterFormat.HighlightColor.Name", "Yellow");
17+
// Check if any matching text ranges were found
18+
if (textRanges != null)
19+
{
20+
// Create or overwrite the text file
21+
using (StreamWriter writer = new StreamWriter(Path.GetFullPath(@"Output/result.txt"), false))
22+
{
23+
if (textRanges != null)
24+
{
25+
//Iterate and write the highlight color name of the current text range to the file
26+
foreach (Entity entity in textRanges)
27+
{
28+
WTextRange textRange = entity as WTextRange;
29+
writer.WriteLine($"HighlightColor: {textRange.CharacterFormat.HighlightColor.Name}");
30+
writer.WriteLine($"Text: {textRange.Text}");
31+
writer.WriteLine(); // Blank line between entries
32+
}
33+
}
34+
else
35+
{
36+
// If no highlighted text ranges were found, write a message to the file
37+
writer.WriteLine("No text ranges with highlight were found.");
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
45+
}
46+
}
47+

0 commit comments

Comments
 (0)