Skip to content

Commit 590cf96

Browse files
ES-876611-Replace-list-restart-numbering-HTML-with-text
1 parent 102d5f1 commit 590cf96

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-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.11.35327.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-list-restart-numbering-HTML-with-text", "Replace-list-restart-numbering-HTML-with-text\Replace-list-restart-numbering-HTML-with-text.csproj", "{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}"
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+
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.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 = {ADDC6FEE-8718-4B00-B091-6C4DC0CBF62A}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<p>
2+
<br/>
3+
</p>
4+
<ol level="1">
5+
<li>
6+
<p>
7+
<span>Mountain 200</span>
8+
</p>
9+
</li>
10+
<li>
11+
<p>
12+
<span>
13+
<span>Mountain 300</span>
14+
<br/>
15+
</span>
16+
</p>
17+
</li>
18+
</ol>
19+
<p>
20+
<br/>
21+
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Replace_list_restart_numbering_HTML_with_text
5+
{
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
// Load the input Word document from file stream
11+
using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read))
12+
{
13+
// Open the Word document
14+
using (WordDocument document = new WordDocument(docStream, FormatType.Docx))
15+
{
16+
// Load the input Word document from file stream
17+
using (FileStream htmlStream = new FileStream(Path.GetFullPath(@"Data/sample.html"), FileMode.Open, FileAccess.Read))
18+
{
19+
// Open the Word document
20+
using (WordDocument replaceDoc = new WordDocument(htmlStream, FormatType.Html))
21+
{
22+
//Replace the first word with HTML file content
23+
document.Replace("Tag1", replaceDoc, true, true);
24+
//Get the paragraph count
25+
int oldcount = document.LastSection.Paragraphs.Count;
26+
//Replace the second word with the HTML file content
27+
document.Replace("Tag2", replaceDoc, true, true);
28+
//Enable restart numbering for the HTML file first paragraph
29+
document.LastSection.Paragraphs[oldcount].ListFormat.RestartNumbering = true;
30+
//Iterate through the remaining paragraphs in the document
31+
for (int i = oldcount + 1; i < document.LastSection.Paragraphs.Count; i++)
32+
{
33+
// If existing list style presents, then continue list numbering
34+
if (document.LastSection.Paragraphs[i].ListFormat.CurrentListStyle != null)
35+
document.LastSection.Paragraphs[i].ListFormat.ContinueListNumbering();
36+
}
37+
38+
// Save the modified document to a new file
39+
using (FileStream docStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
40+
{
41+
document.Save(docStream1, FormatType.Docx);
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Replace_list_restart_numbering_HTML_with_text</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\sample.html">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\Template.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\.gitkeep">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>

0 commit comments

Comments
 (0)