我得到了这个例外
线程中的异常" main" java.lang.NoClassDefFoundError: org / apache / xmlbeans / XmlException at 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");
答案 0 :(得分:0)
您需要下载并将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>