I have my text saved in DB as HTML with all styling and formating. Could please anyone tell me how I can convert that HTML back to Rich Text (I am using word "Rich Text" becoz this is not a plan text instead it has all the styling and formating) and than how I can inject that text in my OpenXML Word Document. I am using C#.
Kind Regards,
Hi,
You cannot directly add Html text to word document. You need to parse Html and convert the tags and values to equivalent open xml word objects. Its a time consuming job if you are planning to write by your own. Instead I would suggest you to go for existing Html To OpenXml parser. This parser converts Html string to OpenXmlElement object. I hope you can do the rest.
You can find the parser here.
Hi Waseem – I actually replied on this thread regarding creating charts in C# in a spreadsheet. For importing HTML out of a database into a DOCX document, you can try OfficeWriter as well. Using the WordTemplate API, you can embed either HTML or RTF content from a database into your DOCX template. You can take a look at the docs here.
Disclaimer: I am one of the developers on the OfficeWriter team. Let me know if you have any questions! -Ozgur