我刚刚开始学习 Apache POI,我想在 Excel 中制作一个 super 简单的电子表格,就像这样,
+----------+----------+----------+----------+----------+
| 1 | 2 | 3 | 4 | 5 |
+----------+----------+----------+----------+----------+
我写的代码如下,
public void exportTable() throws IOException
{
FileOutputStream fos=new FileOutputStream(new File("C:\\Users\\*****\\OneDrive\\Desktop\\excel.xlsx"));
XSSFWorkbook wb=new XSSFWorkbook();
XSSFSheet ws=wb.createSheet();
XSSFRow row=ws.createRow(0);
for(int i=0;i<=5;i++)
{
Cell cell=row.createCell(i);
cell.setCellValue(i);
}
wb.write(fos);
fos.close();
}
我收到 NoClassDefFoundError
我正在使用以下 jar 文件。
1)poi-4.1.0.jar
2)poi-examples-4.1.0.jar
3)poi-excelant-4.1.0.jar
4)poi-ooxml-4.1.0.jar
5)poi-ooxml-schemas-4.1.0.jar
6)poi-scratchpad-4.1.0.jar
7)xmlbeans-3.1.0.jar
8)curvesapi-1.06.jar
我在 netbeans 上使用 jdk 1.8
附注我对 Apache POI 的经验几乎为零,因此如果您能写出详细的答案,我将不胜感激。谢谢
P.P.S。 我不知道 Maven
编辑:所以我改变了一些东西
1)我从“common-collections”导入了所有jar文件。
2)我将“.xls”更改为“.xlsx”
3)我还导入了“common-compress”,现在它工作得很好。谢谢!
最佳答案
错误消息指出: java.lang.NoClassDefFoundError:org/apache/commons/collections4/ListValuedMap
来自 Apache 的 commons-collections4 库。 https://commons.apache.org/proper/commons-collections/ 看来你的类路径上没有这个库。
对于 Maven,使用此依赖项:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
关于java - 如何在 Java 中使用 Apache POI 创建 Excel 电子表格时修复 NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56107659/