1

I have below format .docx format. i want to convert .docx to .html save it in below path:

I have more that 200 .docx file. It's very harder to change into .html manually.

.docx format:

<START>
<TITLE>UAE0d23376</TITLE>
<BODY>
<P>3376</P>
<P>
urged that he should be sent to saint winifreds, with some vague notion of making a man of him. he<br>might as well have thrown a piece of brussels lace into the fire with intention of changing it into<br>you want be troubled with this one long, said her son; ill go with me, and that's soon 
</P>
</BODY>
<END>

Nead to change to .html and save to under "c:\ConvertedToHTML"

can you please help me to solve this.

1 Answer 1

1

Convert .docx file to HTML format

Add reference to OpenXmlPowerTools.dll 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());
 }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.