编写使用Apache POI在XLSX格式的文件 [英] Write a file in xlsx format using Apache POI
问题描述
我收到以下异常试图写使用Apache POI的 .xlsx文件
I am getting the following exception while trying to write an .xlsx file using Apache POI
NoClassDefFoundError: javax/xml/stream/XMLStreamException
这里的code段: -
Here's the Code Snippet:-
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文件包含
I have the following jars included
- 的dom4j-1.6.1
- POI-OOXML-3.5-FINAL
- POI-3.6-20091214
- 的XMLBeans-2.3.0
- OOXML-架构-1.0
请让我知道我在做什么错在这里就是我失去了一些东西。
Please let me know what i am doing wrong here or i am missing something.
推荐答案
您错过了STAX API JAR
You're missing the stax API jar
如果你看一下 POI组件页面你会看到OOXML-模式罐子取决于STAX的API罐子(最典型的是所提供的 STAX-API-1.0.1.jar
)
If you look at the POI Components page you'll see that the ooxml-schemas jar depends on a STAX API jar (most typically provided by stax-api-1.0.1.jar
)
看着你的POI二进制下载,并在 OOXML-LIB
目录,你会看到你所需要的罐子。另外,如果你使用Maven,它会下载依赖你。
Look in your POI binary download, and in the ooxml-lib
directory you'll see the jar you need. Alternately, if you use Maven, it'll download the dependency for you
这篇关于编写使用Apache POI在XLSX格式的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!