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

Add find and replace samples #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions Find-and-Replace/Find-match-case/.NET/Find-match-case.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35417.141 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-match-case", "Find-match-case\Find-match-case.csproj", "{51F6D2BA-42F2-4921-A14E-E23C3462B09A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51F6D2BA-42F2-4921-A14E-E23C3462B09A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
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_match_case</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Template.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 @@

25 changes: 25 additions & 0 deletions Find-and-Replace/Find-match-case/.NET/Find-match-case/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.Drawing;

using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
{
//Finds the first occurrence of a particular text in the document.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Finds the first occurrence of a particular text that matches the exact case in the document.

TextSelection textSelection = document.Find("adventure", true, false);
//Gets the found text as single text range.
WTextRange textRange = textSelection.GetAsOneRange();
//Modifies the text.
textRange.Text = "Replaced text";
//Sets highlight color.
textRange.CharacterFormat.HighlightColor = Color.Yellow;
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35417.141 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83A04CC7-7718-4BE2-979B-167DBE12DF36}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
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_in_Word_document</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Template.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,25 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.Drawing;

using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
{
//Finds the first occurrence of a particular text in the document.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Finds the first occurrence of a particular text that matches whole words in the document.

TextSelection textSelection = document.Find("Adventure Works Cycles", false, true);
//Gets the found text as single text range.
WTextRange textRange = textSelection.GetAsOneRange();
//Modifies the text.
textRange.Text = "Replaced text";
//Sets highlight color.
textRange.CharacterFormat.HighlightColor = Color.Yellow;
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35417.141 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-whole-words-only", "Find-whole-words-only\Find-whole-words-only.csproj", "{8D737D63-1B30-4FBC-910F-D264B797BA7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D737D63-1B30-4FBC-910F-D264B797BA7A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
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_whole_words_only</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<None Update="Data\Template.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,25 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.Drawing;

using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
{
//Finds the first occurrence of a particular text in the document.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Finds the first occurrence of a particular text that matches whole words in the document.

TextSelection textSelection = document.Find("AdventureWorks", false, true);
//Gets the found text as single text range.
WTextRange textRange = textSelection.GetAsOneRange();
//Modifies the text.
textRange.Text = "Replaced text";
//Sets highlight color.
textRange.CharacterFormat.HighlightColor = Color.Yellow;
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
}