Page 1 of 1

Converting HTML

PostPosted: Fri Jul 23, 2010 10:08 pm
by cyroluxx
Hello everybody,

As i am a rookie in using this framework, i have a question about using HTML-Tags in the source code. I want to add html-code into a table.

For example:
String s = "Text</br>" + "</br>" + "break</br>" + "</br>";

Now i want to convert this string into a representing form, docx4j can handle this.

Is this possible?

Greetz,
Cyroluxx

(And sorry about my bad english :) )

Re: Converting HTML

PostPosted: Sat Jul 24, 2010 11:47 pm
by jason
WordML includes "altChunk", which you can use to include HTML content directly in a document. You'll have to have a look to see whether this works in a table cell.

docx4j doesn't have anything beyond this for including html content. If your string is just text + line break elements, converting that into a WordML w:p would be pretty easy.

---------------

If you wanted to create the table itself from HTML:-

I do have some code somewhere for converting an HTML table to a docx table, but its not currently part of docx4j. TableModel has a toJAXB method which can make a docx table from docx4j's internal table model. So the bit which is currently missing is to convert an HTML table to that internal table model.

You can also use the altChunk stuff to include HTML in a docx.

For completeness, the usual way to create a table would be from scratch (perhaps with the help of TblFactory) or using XmlUtils.unmarshalString