Skip to content

Commit 753e781

Browse files
Merge pull request #174 from AntonihilSahayaraj/main
Sample for Replace-text-heading-paragraphs
2 parents 08441eb + a3dc5fd commit 753e781

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-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.8.34205.153
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-text-heading-paragraphs", "Replace-text-heading-paragraphs\Replace-text-heading-paragraphs.csproj", "{31049C0F-9DAB-4E86-B673-F016A2739CF8}"
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+
{31049C0F-9DAB-4E86-B673-F016A2739CF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{31049C0F-9DAB-4E86-B673-F016A2739CF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{31049C0F-9DAB-4E86-B673-F016A2739CF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{31049C0F-9DAB-4E86-B673-F016A2739CF8}.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 = {FBED5554-96A4-4724-A0E2-4E607A82259E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+

2+
3+
using Microsoft.VisualBasic.FileIO;
4+
using Syncfusion.DocIO;
5+
using Syncfusion.DocIO.DLS;
6+
7+
namespace Replace_text_heading_paragraphs
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
14+
{
15+
//Opens an existing Word document.
16+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic))
17+
{
18+
for (int headingLevel = 1; headingLevel < 10; headingLevel++)
19+
{
20+
//Find headings based on the levels and endnote by paragraph in Word document.
21+
List<Entity> headings = document.FindAllItemsByProperty(EntityType.Paragraph, "StyleName", "Heading " + headingLevel);
22+
//Replace the headings with text.
23+
for (int index = 0; index < headings.Count; index++)
24+
{
25+
WParagraph paragraph = headings[index] as WParagraph;
26+
paragraph.ChildEntities.Clear();
27+
paragraph.AppendText("Replaced Heading"+headingLevel+" text");
28+
}
29+
}
30+
//Creates file stream.
31+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite))
32+
{
33+
//Saves the Word document to file stream.
34+
document.Save(outputFileStream, FormatType.Docx);
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>Replace_text_heading_paragraphs</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+
</Project>

0 commit comments

Comments
 (0)