Skip to content

Commit 8723130

Browse files
Merge pull request #322 from SyncfusionExamples/883097-Find-and-replace
883097-Add find and replace samples
2 parents df9c98d + 63397f2 commit 8723130

File tree

20 files changed

+219
-3
lines changed

20 files changed

+219
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35417.141 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-match-case", "Find-match-case\Find-match-case.csproj", "{51F6D2BA-42F2-4921-A14E-E23C3462B09A}"
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+
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
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_match_case</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\Template.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using Syncfusion.Drawing;
4+
5+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
6+
{
7+
//Opens an existing Word document.
8+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
9+
{
10+
// Finds the first occurrence of a particular text that matches the exact case in the document.
11+
TextSelection textSelection = document.Find("adventure", true, false);
12+
//Gets the found text as single text range.
13+
WTextRange textRange = textSelection.GetAsOneRange();
14+
//Modifies the text.
15+
textRange.Text = "Replaced text";
16+
//Sets highlight color.
17+
textRange.CharacterFormat.HighlightColor = Color.Yellow;
18+
//Creates file stream.
19+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
20+
{
21+
//Saves the Word document to file stream.
22+
document.Save(outputFileStream, FormatType.Docx);
23+
}
24+
}
25+
}

Find-and-Replace/Find-and-find-next/.NET/Find-and-find-next.sln renamed to Find-and-Replace/Find-next/.NET/Find-next.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.31911.196
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-and-find-next", "Find-and-find-next\Find-and-find-next.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-next", "Find-next\Find-next.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0</TargetFramework>
6-
<RootNamespace>Find_and_find_next</RootNamespace>
6+
<RootNamespace>Find_next</RootNamespace>
77
</PropertyGroup>
88

99
<ItemGroup>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


Find-and-Replace/Find-and-find-next/.NET/Find-and-find-next/Program.cs renamed to Find-and-Replace/Find-next/.NET/Find-next/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Syncfusion.Drawing;
44
using System.IO;
55

6-
namespace Find_and_find_next
6+
namespace Find_next
77
{
88
class Program
99
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35417.141 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-in-Word-document", "Find-text-in-Word-document\Find-text-in-Word-document.csproj", "{83A04CC7-7718-4BE2-979B-167DBE12DF36}"
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+
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
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_in_Word_document</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\Template.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using Syncfusion.Drawing;
4+
5+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
6+
{
7+
//Opens an existing Word document.
8+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
9+
{
10+
// Finds the first occurrence of a particular text that matches whole words in the document.
11+
TextSelection textSelection = document.Find("Adventure Works Cycles", false, true);
12+
//Gets the found text as single text range.
13+
WTextRange textRange = textSelection.GetAsOneRange();
14+
//Modifies the text.
15+
textRange.Text = "Replaced text";
16+
//Sets highlight color.
17+
textRange.CharacterFormat.HighlightColor = Color.Yellow;
18+
//Creates file stream.
19+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
20+
{
21+
//Saves the Word document to file stream.
22+
document.Save(outputFileStream, FormatType.Docx);
23+
}
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35417.141 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-whole-words-only", "Find-whole-words-only\Find-whole-words-only.csproj", "{8D737D63-1B30-4FBC-910F-D264B797BA7A}"
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+
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
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_whole_words_only</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\Template.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using Syncfusion.Drawing;
4+
5+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
6+
{
7+
//Opens an existing Word document.
8+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
9+
{
10+
// Finds the first occurrence of a particular text that matches whole words in the document.
11+
TextSelection textSelection = document.Find("AdventureWorks", false, true);
12+
//Gets the found text as single text range.
13+
WTextRange textRange = textSelection.GetAsOneRange();
14+
//Modifies the text.
15+
textRange.Text = "Replaced text";
16+
//Sets highlight color.
17+
textRange.CharacterFormat.HighlightColor = Color.Yellow;
18+
//Creates file stream.
19+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
20+
{
21+
//Saves the Word document to file stream.
22+
document.Save(outputFileStream, FormatType.Docx);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)