Skip to content

Commit fe5dafa

Browse files
Added sample
1 parent 1cfc871 commit fe5dafa

7 files changed

Lines changed: 167 additions & 0 deletions

File tree

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.14.37111.16 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Save-HTML-From-Word-Document", "Save-HTML-From-Word-Document\Save-HTML-From-Word-Document.csproj", "{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}"
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+
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.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 = {6E0ACDC8-D80C-4DBF-BD66-0BB0FDE4BF92}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


HTML-conversions/Save-HTML-From-Word-Document/.NET/Save-HTML-From-Word-Document/Save-HTML-From-Word-Document/Output/OddHeader_0.html

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

HTML-conversions/Save-HTML-From-Word-Document/.NET/Save-HTML-From-Word-Document/Save-HTML-From-Word-Document/Output/TextBody.html

Lines changed: 48 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Save_HTML_From_Word_Document
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"../../../Data/Template.docx"), FileMode.Open, FileAccess.Read))
11+
{
12+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
13+
{
14+
int i = 0;
15+
foreach (WSection section in document.Sections)
16+
{
17+
if (section.PageSetup.DifferentFirstPage)
18+
{
19+
GenerateHTML(section.HeadersFooters.FirstPageHeader, "FirstPageHeader_" + i + ".html");
20+
GenerateHTML(section.HeadersFooters.FirstPageFooter, "FirstPageFooter_" + i + ".html");
21+
}
22+
else if (section.PageSetup.DifferentOddAndEvenPages)
23+
{
24+
GenerateHTML(section.HeadersFooters.EvenHeader, "EvenHeader_" + i + ".html");
25+
GenerateHTML(section.HeadersFooters.EvenFooter, "EvenFooter_" + i + ".html");
26+
27+
}
28+
//This is the default header and footer
29+
GenerateHTML(section.HeadersFooters.OddHeader, "OddHeader_" + i + ".html");
30+
GenerateHTML(section.HeadersFooters.OddFooter, "OddFooter_" + i + ".html");
31+
32+
//After generating headers and footers, clear it
33+
section.HeadersFooters.FirstPageHeader.ChildEntities.Clear();
34+
section.HeadersFooters.FirstPageFooter.ChildEntities.Clear();
35+
section.HeadersFooters.EvenHeader.ChildEntities.Clear();
36+
section.HeadersFooters.EvenFooter.ChildEntities.Clear();
37+
section.HeadersFooters.OddHeader.ChildEntities.Clear();
38+
section.HeadersFooters.OddFooter.ChildEntities.Clear();
39+
40+
i++;
41+
}
42+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Output/TextBody.html"), FileMode.Create))
43+
{
44+
document.Save(outputStream, FormatType.Html);
45+
}
46+
}
47+
}
48+
}
49+
private static void GenerateHTML(WTextBody textBody, string outputFile)
50+
{
51+
string outputPath = Path.GetFullPath(@"../../../Output/");
52+
if (textBody.ChildEntities.Count > 0)
53+
{
54+
WordDocument document = new WordDocument();
55+
document.AddSection();
56+
foreach (Entity entity in textBody.ChildEntities)
57+
document.LastSection.Body.ChildEntities.Add(entity.Clone());
58+
59+
document.Save(outputPath + outputFile, FormatType.Html);
60+
}
61+
}
62+
63+
}
64+
}
65+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Save_HTML_From_Word_Document</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
12+
</ItemGroup>
13+
<ItemGroup>
14+
<None Update="Data\Input.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
</Project>

0 commit comments

Comments
 (0)