Page 1 of 1

Converting HTML tables to word tables

PostPosted: Fri May 11, 2012 7:40 am
by conphident4
Hi,
I am trying to convert HTML table to word based on the XHTMLImportFragment.java example provided. However, when I try to do that, I am getting the following error:
Code: Select all
Exception in thread "main" java.lang.ClassCastException: org.docx4j.org.xhtmlrenderer.newtable.TableSectionBox cannot be cast to org.docx4j.org.xhtmlrenderer.newtable.TableBox
   at org.docx4j.convert.in.xhtml.Importer.traverse(Importer.java:463)
   at org.docx4j.convert.in.xhtml.Importer.traverse(Importer.java:746)
   at org.docx4j.convert.in.xhtml.Importer.traverse(Importer.java:746)
   at org.docx4j.convert.in.xhtml.Importer.convert(Importer.java:382)
   at org.docx4j.samples.XHTMLImportFragment.main(XHTMLImportFragment.java:95)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


This is the sample table that I am trying to import into word

Code: Select all
"<table class=\"reference\" style=\"width:60%\">\n" +
                "\t<tr>\n" +
                "\t\t<td>Apples</td>\n" +
                "\t\t<td>44%</td>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>Bananas</td>\n" +
                "\t\t<td>23%</td>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>Oranges</td>\n" +
                "\t\t<td>13%</td>\n" +
                "\t</tr>\n" +
                "\t<tr>\n" +
                "\t\t<td>Other</td>\n" +
                "\t\t<td>10%</td>\n" +
                "\t</tr>\n" +
                "</table>\n";


Please let me know if someone has successfully imported HTML tables into word. I am using the 2.8.0 SNAPSHOT as code base.

Re: Converting HTML tables to word tables

PostPosted: Sun May 20, 2012 7:12 pm
by jason