【发布时间】:2015-02-13 06:31:38
【问题描述】:
我想通过 poi 将 docx 转换为 html。我正在使用以下代码
...
XWPFDocument document = new XWPFDocument(is);
XHTMLOptions options = XHTMLOptions.create();
OutputStream out = new FileOutputStream(htmlFile);
XHTMLConverter.getInstance().convert(document, out, options);
...
在最后一行我得到了异常
java.lang.NoSuchMethodError: org.apache.poi.xwpf.usermodel.XWPFHyperlinkRun.<init>(Lorg/openxmlformats/schemas/wordprocessingml/x2006/main/CTHyperlink;Lorg/openxmlformats/schemas/wordprocessingml/x2006/main/CTR;Lorg/apache/poi/xwpf/usermodel/XWPFParagraph;)V
我正在使用以下库:
POI 3.10Final
org.apache.poi.xwpf.converter.core 1.0.4.jar
org.apache.poi.xwpf.converter.xhtml 1.0.4.jar
问题是 core 和 xhtml 库使用 3.09 版本的 POI,其中有构造函数 XWPFHyperlinkRun(CTHyperlink hyperlink, CTR run, XWPFParagraph p),但 3.10 版本有构造函数 XWPFHyperlinkRun(CTHyperlink hyperlink, CTR run, IRunBody p)。
我无法降级 poi,因为我在其他地方使用 3.10 的功能,并且 core/xhtml 库没有比 1.0.4 更新的版本。我尝试使用 docx4j 库,但有一些问题,但如果可以选择使用 poi 而不是其他库,我会更喜欢。
有没有办法解决这个问题?
感谢您的回答
【问题讨论】:
-
Apache POI 不提供任何名为
org.apache.poi.xwpf.converter之类的 jar - 这些 jar 真正来自哪里? -
不知道同事在哪里找到这些(1.0.0 版在我尝试将它们更新到 1.0.4 版之前已经存在)mvnrepository.com/artifact/fr.opensagres.xdocreport/…mvnrepository.com/artifact/fr.opensagres.xdocreport/…
-
那不是 Apache POI 的一部分,那是一些外部组。您需要与他们取得联系并要求他们制作新版本/下载他们的源代码并重新编译。 3.9 到 3.10/3.11 是源代码兼容的,但有一些位(例如 this)不是二进制兼容的,所以你需要重新编译
标签: java html apache-poi docx nosuchmethoderror