我刚刚开始学习Apache POI我想在excel中制作一个类似这样的超级简单的电子表格,
+----------+----------+----------+----------+----------+
| 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-例子-4.1.0.jar
3)POI-excelant-4.1.0.jar
4)POI-OOXML-4.1.0.jar
5)POI-OOXML-架构 - 4.1.0.jar
6)POI暂存器-4.1.0.jar
7)的xmlbeans-3.1.0.jar
8)curvesapi-1.06.jar
我在netbeans上使用jdk 1.8
PS我对Apache POI几乎没有经验,所以如果你能写一个详细的答案,我将不胜感激。谢谢
PPS 我不认识Maven
编辑:所以我改变了一些事情
1)我从“common-collections”导入了所有jar文件。
2)我将“.xls”改为“.xlsx”
3)我也导入了“common-compress”,现在它完美无缺。谢谢!