Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

java - Table with margins attribute as list item throws exception ClassCastException

I am using

org.docx4j.convert.in.xhtml.XHTMLImporterImpl

And when I call convert(html, ""); with following html:

<ul>
    <li>first list item</li>
    <li>
        <table style="margin-left: auto; margin-right: auto; width: 75%; table-layout: fixed;">
            <tbody>
            <tr>
                <td>
                    <p>ROW</p>
                </td>
            </tr>
            </tbody>
        </table>
    </li>
</ul>

I get the following stack trace:

    java.lang.ClassCastException: class org.docx4j.org.xhtmlrenderer.css.constants.IdentValue cannot be cast to class org.docx4j.org.xhtmlrenderer.css.style.derived.LengthValue (org.docx4j.org.xhtmlrenderer.css.constants.IdentValue and org.docx4j.org.xhtmlrenderer.css.style.derived.LengthValue are in unnamed module of loader 'app')
    at org.docx4j.convert.in.xhtml.ListHelper.getAbsoluteIndent(ListHelper.java:381)
    at org.docx4j.convert.in.xhtml.TableHelper.setupTblPr(TableHelper.java:120)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1020)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:1284)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.traverse(XHTMLImporterImpl.java:825)
    at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:698)

I can tell that it is caused by margin-left and margin-right in the style attribute for the table because if I remove those convert() doesn't thrown an exception. Does anyone know any workaround for this that doesn't involve removing margins from the table?

question from:https://stackoverflow.com/questions/65904371/table-with-margins-attribute-as-list-item-throws-exception-classcastexception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

margin-left is usually a length, but because of the value "auto", here it is an IdentValue.

https://github.com/plutext/docx4j-ImportXHTML/commit/466d2d01983333c3c4e456aea926f99bb4755016 ignores it if it is an IdentValue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...