Page 1 of 1

Display Plain html text as Rich Text in Word

PostPosted: Wed Aug 27, 2014 11:38 pm
by praveen065
Hi Jason,
I am reading a Word document with Table having Rows and Cells with place holders. After unmarshalling the word document, I iterate through the rows of the table and replace the placeholders with the values. I could replace the placeholders with other texts, checkbox, radio button,table, etc.,
Now I want to replace the placeholder with a html content (
Code: Select all
<h1>Heading</h1><b>hi</b>
) such that I want to see the replaced values with new styles. Could you help in converting and displaying the text in the output document. Thanks in advance.

Regards,
Praveen_J

Re: Display Plain html text as Rich Text in Word

PostPosted: Thu Aug 28, 2014 12:07 pm
by jason
You can use docx4j-ImportXHTML (though you have to feed it well formed XML)

See the sample code at https://github.com/plutext/docx4j-Impor ... gment.java

The neatest solution is to use content control data binding. If an XPath points to an element containing escaped XHTML, the OpenDoPE code will automatically convert that escaped XHTML to docx content (and insert it).

An alternative to docx4j-ImportXHTML is to insert an altChunk of type HTML, then leave it to Word to convert it to docx content. However, I'd expect docx4j-ImportXHTML to give you better results.