Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37111.16 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFD82BD1-243F-86F6-FB0C-E6FB6CF11614}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6E0ACDC8-D80C-4DBF-BD66-0BB0FDE4BF92}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@


Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace Save_HTML_From_Word_Document
{
class Program
{
static void Main(string[] args)
{
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"../../../Data/Template.docx"), FileMode.Open, FileAccess.Read))
{
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
int i = 0;
foreach (WSection section in document.Sections)
{
if (section.PageSetup.DifferentFirstPage)
{
GenerateHTML(section.HeadersFooters.FirstPageHeader, "FirstPageHeader_" + i + ".html");
GenerateHTML(section.HeadersFooters.FirstPageFooter, "FirstPageFooter_" + i + ".html");
}
else if (section.PageSetup.DifferentOddAndEvenPages)
{
GenerateHTML(section.HeadersFooters.EvenHeader, "EvenHeader_" + i + ".html");
GenerateHTML(section.HeadersFooters.EvenFooter, "EvenFooter_" + i + ".html");

}
//This is the default header and footer
GenerateHTML(section.HeadersFooters.OddHeader, "OddHeader_" + i + ".html");
GenerateHTML(section.HeadersFooters.OddFooter, "OddFooter_" + i + ".html");

//After generating headers and footers, clear it
section.HeadersFooters.FirstPageHeader.ChildEntities.Clear();
section.HeadersFooters.FirstPageFooter.ChildEntities.Clear();
section.HeadersFooters.EvenHeader.ChildEntities.Clear();
section.HeadersFooters.EvenFooter.ChildEntities.Clear();
section.HeadersFooters.OddHeader.ChildEntities.Clear();
section.HeadersFooters.OddFooter.ChildEntities.Clear();

i++;
}
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Output/TextBody.html"), FileMode.Create))
{
document.Save(outputStream, FormatType.Html);
}
}
}
}
private static void GenerateHTML(WTextBody textBody, string outputFile)
{
string outputPath = Path.GetFullPath(@"../../../Output/");
if (textBody.ChildEntities.Count > 0)
{
WordDocument document = new WordDocument();
document.AddSection();
foreach (Entity entity in textBody.ChildEntities)
document.LastSection.Body.ChildEntities.Add(entity.Clone());

document.Save(outputPath + outputFile, FormatType.Html);
}
}

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Save_HTML_From_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>
Loading