2

I am using the DOCX library to manipulate *.docx files.

I would like to save a *docx file as an html file, but this code:

using (DocX sourceDoc = DocX.Create(sourceFilename))
{
    sourceDoc.SaveAs(sourceHTMLFileName); 
}

...does not work (sourceHTMLFileName is "Bla.html").

Is it possible? If so, how?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

2

The author of DocX has stated in a blog post that his library does not support this feature yet. I got the link from the codeplex page for the library.)

Quote from the link:

I would love to add this functionality to DocX, however there is a problem.

[...]

The only easy way to do this conversion, is to use Microsoft’s Office interop libraries

[...]

Is there no way to do conversions without having Word.exe installed on my machine. I didn’t say that, I said there is no easy way. This looks very promising, now if I could only find the time.

He suggests a workaround using Interop but that might not be possible depending on your environment.

Using SaveAs with a file that ends in .html simply saves a .docx file with the wrong extension; there is no conversion done.

Community
  • 1
  • 1
dee-see
  • 23,668
  • 5
  • 58
  • 91
  • "Using SaveAs with a file that ends in .html simply saves a .docx file with the wrong extension; there is no conversion done." Yes, I noticed. – B. Clay Shannon-B. Crow Raven Feb 17 '14 at 22:50
  • I think you have to use your own implementation to read data from the word and convert to html. `MagicText` has `FormattedText` property where you can get style information for text but you cannot get the positions. Better to use `OpenXml` libraries and use `HtmlConverter` class – xwpdev Jun 12 '15 at 06:24