gpt4 book ai didi

java - 从 csv 转换为 excel 期间出现 NoClassDefFoundError

转载 作者:太空宇宙 更新时间:2023-11-04 11:04:29 24 4
gpt4 key购买 nike

我遇到了这个异常

Exception in thread "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");

最佳答案

您需要下载 XML beans 依赖项并将其添加到您的类路径中。该库通常称为 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>

关于java - 从 csv 转换为 excel 期间出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46600427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com