尝试使用 Apache POI 编写 .xlsx 文件时出现以下异常
NoClassDefFoundError: javax/xml/stream/XMLStreamException
这是代码片段:-
XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(100);
FileOutputStream fileOut = new FileOutputStream("D:\\workspace\\April\\Excel Test\\workbook.xlsx");
wb.write(fileOut);
fileOut.close();
我有以下 jar
- dom4j-1.6.1
- poi-ooxml-3.5-FINAL
- poi-3.6-20091214
- xmlbeans-2.3.0
- ooxml-schemas-1.0
请让我知道我在这里做错了什么或者我遗漏了什么。
最佳答案
您缺少 stax API jar
如果您查看 POI Components page您会看到 ooxml-schemas jar 依赖于 STAX API jar(通常由 stax-api-1.0.1.jar
提供)
查看您的 POI 二进制下载,在 ooxml-lib
目录中您会看到您需要的 jar。或者,如果您使用 Maven,它会为您下载依赖项
关于java - NoClassDefFoundError : javax/xml/stream/XMLStreamException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400096/