We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Syncfusion Feedback


Trusted by the world’s leading companies

Overview

HTML, the standard markup language that shapes the structure of webpages, serves as the foundation for online content. Now, with the use of the Syncfusion .NET Word Library (DocIO), you can seamlessly convert HTML to Word documents and Word documents to HTML in C#. Simplify your HTML conversion tasks without installing Microsoft Office on your machine.


How to convert HTML to Word documents in C#

  1. Install NuGet package: Install the Syncfusion.DocIO.Net.Core NuGet package in your project.
  2. Open HTML file: Create a FileStream object to represent the input HTML file.
  3. Load in .NET Word Library: Create a WordDocument object by passing the FileStream object.
  4. Convert HTML to Word: Save the WordDocument object to the FileStream object in DOCX format.

Here is an example of how to convert HTML to Word files in C# using the Syncfusion .NET Word Library (DocIO).

//Load an existing HTML file.
using FileStream inputFileStream = new FileStream("Input.html", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using WordDocument document = new WordDocument(inputFileStream, FormatType.Html);

//Save the Word document as DOCX format.
using FileStream outputFileStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite);
document.Save(outputFileStream, FormatType.Docx);

Customize HTML-to-Word conversion

Insert HTML snippets

Smoothly integrate HTML snippets into an existing Word document, either at specific positions or by appending them to designated paragraphs, including their formatting.

Customize images

Leverage .NET Word Library’s event handler to personalize images on the fly while importing HTML. Retrieve images from local storage, online websites, or cloud storage and seamlessly replace HTML image sources.


How to convert a Word document to HTML in C#

  1. Install NuGet package: Install the Syncfusion.DocIO.Net.Core NuGet package in your project.
  2. Open Word document: Create a FileStream object to represent the input Word document.
  3. Load in .NET Word Library: Create a WordDocument object by passing the FileStream object.
  4. Convert Word to HTML: Save the WordDocument object to the FileStream object in HTML format.

Here is an example of how to convert a Word document to HTML in C# using the Syncfusion .NET Word Library (DocIO).

//Load an existing Word document.
using FileStream inputFileStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using WordDocument document = new WordDocument(inputFileStream, FormatType.Docx);

//Save as an HTML file.
using FileStream outputFileStream = new FileStream("Result.html", FileMode.Create, FileAccess.ReadWrite);
document.Save(outputFileStream, FormatType.Html);

Customize Word-to-HTML conversion

Customize image path

Utilize the event handler to customize image saving during Word-to-HTML conversion. Use the handler to save images locally or upload them to cloud storage and use the generated path as the image source in the final HTML.

Omit XML declaration

Exclude the XML declaration in the exported HTML file for a lighter and cleaner structure.

Editable fields

Choose between exporting text form fields as editable fields or plain text.




Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion is proud to hold the following industry awards.

Scroll up icon