Search code examples
c#power-tools-for-xml

How to convert word to html using power tool xml


I'm using PowerToolXml.dll as a reference to convert word to HTML this is my code

using OpenXmlPowerTools;
using DocumentFormat.OpenXml.Wordprocessing;

byte[] byteArray = File.ReadAllBytes(DocxFilePath);
using (MemoryStream memoryStream = new MemoryStream())
{
    memoryStream.Write(byteArray, 0, byteArray.Length);
    using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
    {
        HtmlConverterSettings settings = new HtmlConverterSettings()
        {
            PageTitle = "My Page Title"
        };
        XElement html = HtmlConverter.ConvertToHtml(doc, settings);

        File.WriteAllText(HTMLFilePath, html.ToStringNewLineOnAttributes());
    }
}

But produces error at WordprocessingDocument this is not referred (i.e it produce not reference error) how to solve this problem?


Solution

  • The sample code uses the classes and enumerations that are in the DocumentFormat.OpenXml.dll assembly that is installed with the Open XML SDK 2.0 for Microsoft Office. To add the reference to the assembly in the following steps or to build the sample code that accompanies this visual how-to, you must first download and install the Open XML SDK 2.0 for Microsoft Office so that the assembly is available

    You'll find the link to the article below but for your convenience I have summarised it here:

    The reference must be made inside your Visual Studio project. In Solution Explorer, find your project; then expand it; look for References; expand it; and ensure PowerToolXml appears there; if not right-click References and Add Reference to the assembly

    Tell me more