News Category

Convert Word to HTML in WPF

2012-07-25 08:05:32 Written by  support iceblue
Rate this item
(0 votes)

During software development, developers may need to convert Word to HTML. Different from many available ways on Internet, in this example, the solution for converting Word to HTML enables WPF developers load a predefined Doc, Docx, or RTF document, fill it with data, convert the document to HTML.

Spire.Doc for WPF is a professional component specializing in manipulating Word document for WPF. To convert a Word to HTML simply in WPF, developers need to invoke document.LoadFromFile(), which is used to load document and document.SaveToFile(), which is used to convert document.

The following screenshot shows parts of contents of original Word document. The target HTML is at the bottom after this coding. It is shown in Firefox, same as the original document.

Word to HTML

Download and install Spire.Doc for WPF on your system. Then, add a button in MainWindow and double click it to use the following code to convert Word to HTML in WPF

[C#]
using Spire.Doc;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //Load Document
            Document document = new Document();
            document.LoadFromFile(@"E:\work\Documents\Humor Them.docx");

            //Convert to HTML
            document.SaveToFile("ToHTML.html", FileFormat.Html);

            //Launch Document
            System.Diagnostics.Process.Start("ToHTML.html");

        }



    }
}
[VB.NET]
Imports Spire.Doc
Imports System.Windows

Namespace WpfApplication1
	Public Partial Class MainWindow
		Inherits Window
		Public Sub New()
			InitializeComponent()
		End Sub
		Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
			'Load Document
			Dim document As New Document()
			document.LoadFromFile("E:\work\Documents\Humor Them.docx")

			'Convert to HTML
			document.SaveToFile("ToHTML.html", FileFormat.Html)

			'Launch Document
			System.Diagnostics.Process.Start("ToHTML.html")

		End Sub



	End Class
End Namespace

After running, you can get the result as following:

Word to HTML

Spire.Doc is an Microsoft Word component which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF.NET and Silverlight.

Additional Info

  • tutorial_title: Convert Word to HTML in WPF
Last modified on Friday, 24 September 2021 09:52