【发布时间】:2018-09-25 14:24:20
【问题描述】:
我正在测试 Apache POI,但我有问题。
我正在使用 maven 和 java。
- 可以在不阅读的情况下将excel文件转换为PDF(类似于
PdfConverter.getInstance().convert) - 如果没有步骤1中的功能,我该如何保留excel的样式、格式和其他东西?
- 为什么这个代码
PdfConverter.getInstance().convert(doc,outFile,options);有这个错误java.lang.ClassNotFoundException: org.apache.poi.POIXMLDocumentPart(见下面的代码)? - 是否有其他免费的库可供我使用?
我附上了pom.xml和单词转换的代码:
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<!-- org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<!-- org.apache.poi.xwpf.converter.pdf -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.6</version>
</dependency>
<!-- com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
单词转换代码:
File file1 = new File("myWord.docx");
FileInputStream fileInpStr1 = new FileInputStream(file1.getAbsolutePath());
XWPFDocument doc = new XWPFDocument(fileInpStr1);
OutputStream outFile = new FileOutputStream("myPDFout.pdf"));
PdfOptions options = null;
PdfConverter.getInstance().convert(doc,outFile,options); <-- here the error jumps
outFile.close();
doc.close();
【问题讨论】:
-
对于未找到的类,请参阅此答案:stackoverflow.com/questions/26024193/…
-
没有自己尝试,但看起来很有希望github.com/yeokm1/docs-to-pdf-converter
-
fr.opensagres.xdocreport 不支持 poi 4.0.0 - mvnrepository.com/artifact/fr.opensagres.xdocreport/… - 依赖于 poi 3.10-FINAL
-
PJ Fanning 我添加了依赖项并更改了 poi 版本,但我在 XWPFDocument 类中遇到了另一个错误。
-
请花点时间咨询该网站的help center 以提出问题。这是一个问答网站,而不是一个“论坛”。因此,每个“问题”只允许一个问题 - 你问四个。要求图书馆或软件推荐是题外话。您可以使用问题下方的edit 链接使其符合 Stack Overflow 的准则。
标签: java excel maven ms-word apache-poi