Convert Html to Word in .Net

I need to create a word file from HTML content (on an ASP.NET server), but could not find a reliable way to do this. Therefore, we decided to hold a discussion here to find out what options are available to do this.

Aspose has a .NET component for this, but the price is so high, so it cannot be a solution (due to budget problems).

We expect this conversion to save tables, images, hide invisible elements, links, etc.

There is a similar discussion here , but all Office Interop related solutions are not a recommended solution for a server application.

Any idea? Basically, how do components like Aspose work?

+4
source share
4 answers

I would suggest writing code using the OpenXml API, you can navigate the DOM and programmatically add elements to the word document. This is not an easy task because you are interpreting the markup and trying to transform it.

link for Open XML: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5124

+3
source

Is hard work already done? The project seems to be on codeplex.

Blog post describing the HTML for the docx converter
Codeplex Project

+9
source

It might be worth checking out Microsoft's own XSLT Inference tool, which can generate WordML with XML input.

If you are flexible in that the source of the document itself is HTML / XHTML / XML, this can easily complete the task.

http://msdn.microsoft.com/en-us/library/aa212886%28v=office.11%29.aspx

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3412

I used it in the past to create Word documents from an ASP.NET application that retrieved XML source data from SQL stored procedures.

The tool may be a bit temperamental, but with the small amount of XSLT sanitization that it generates, it can just work.

+1
source

If docx is applicable, you can create a text document, save it as docx, reverse engineer xml and create your own xml / docx. I did this with excel / xslx and it worked perfectly. To speed things up, we created XML as text and joined the lines (before our data - our data - after our data).

The RTF format is not a standard poster, but it is widespread. Create an RTF document and return it as a Word document. Word opens rtf without any problems.

Create an HTML document and return it as a Word document.

NTN

0
source

All Articles