gpt4 book ai didi

java - Apache POI 异常

转载 作者:行者123 更新时间:2023-11-30 07:44:43 27 4
gpt4 key购买 nike

我需要将 docx 转换为 PDF,我将使用 Apache POI。这是我的 POM:

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.0</version>
</dependency>


</dependencies>

出于某种原因,我在转换运行期间遇到异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocumentPart at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.getFontsDocument(XWPFStylesDocument.java:1477) at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.(XWPFStylesDocument.java:190) at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.(XWPFStylesDocument.java:184) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.createStylesDocument(XWPFDocumentVisitor.java:166) at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.(XWPFDocumentVisitor.java:159) at org.apache.poi.xwpf.converter.pdf.internal.PdfMapper.(PdfMapper.java:149) at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55) at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:38) at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45) at temp.main.Teste(main.java:30) at temp.main.main(main.java:18) Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIXMLDocumentPart at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 11 more

我用谷歌搜索试图找到我遗漏的依赖项,至少我认为是这样,但我找不到能够解决我的问题的有关 POIXMLDocumentPart 的信息。

这是我用来转换 docx 的方法:

public static void Teste(File file, String destino) {

try {
InputStream doc = new FileInputStream(file);
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(new File(destino));
PdfConverter.getInstance().convert(document, out, options);
new File(destino);
} catch(Exception e) {

}
}

最佳答案

XDocReport 是针对 POI 3.17 编译的。POI 4.0.0 有一些变化,XDocReport 不适用于 POI 4.0.0。POIXMLDocumentPart 移动到包 org.apache.poi.ooxml。

参见 https://github.com/opensagres/xdocreport/pull/324

更新(2019 年 3 月):Looks XDocReport 2.0.2 已更新为使用 POI 4.0.1。

关于java - Apache POI 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52339378/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com