我收到这个例外
线程“主”中的异常java.lang.NoClassDefFoundError:
org / apache / xmlbeans / XmlException在
com.restcalls.JSONtoCSV.main(JSONtoCSV.java:176)
当我尝试将csv
文件转换为excel
文件时。
此行似乎是引起问题的原因-XSSFWorkbook workBook = new XSSFWorkbook();
。
我已经添加了最新的POI jar
-3.17,这是我的代码:
String xlsxFileAddress = "C:/Users/xxxxx/REST/exports/test.xlsx"; //xlsx file address
System.out.println("here 0");
XSSFWorkbook workBook = new XSSFWorkbook();
System.out.println("here 0.1");
XSSFSheet sheet = workBook.createSheet("sheet1");
System.out.println("here 1");
String currentLine=null;
int RowNum=0;
BufferedReader br = new BufferedReader(new FileReader(csvFileAddress));
System.out.println("here 2: "+br);
while ((currentLine = br.readLine()) != null) {
String str[] = currentLine.split(",");
RowNum++;
XSSFRow currentRow=sheet.createRow(RowNum);
for(int i=0;i<str.length;i++){
currentRow.createCell(i).setCellValue(str[i]);
}
}
FileOutputStream fileOutputStream = new FileOutputStream(xlsxFileAddress);
workBook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("Done");
最佳答案
您需要下载XML Bean依赖性并将其添加到类路径。该库通常称为xmlbeans-x.x.x.jar。例如:搜索并下载xmlbeans-2.6.0.jar,或者如果您具有如下所示的Maven项目设置POM
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>