Skip to content
Open
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.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
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_by_highlight_color</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Input.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,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<Entity> 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.");
}
}
}
}
}
}

}
}

Loading