如何打开的.xlsx与POI SS文件? [英] How to open .xlsx files with POI SS?
问题描述
我试图打开的.xlsx文件,POI SS这个code(从的 http://poi.apache.org/s$p$padsheet/quick-guide.html#ReadWriteWorkbook ):
I am trying to open .xlsx files with POI SS with this code (taken from http://poi.apache.org/spreadsheet/quick-guide.html#ReadWriteWorkbook):
InputStream inp = new FileInputStream("workbook.xls");
//InputStream inp = new FileInputStream("workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
和我得到这个错误信息:
and I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
我的xbean.jar添加到我的图书馆和我的运行时库。
I add the xbean.jar to my library and to my run-time libraries.
我怎么能解决这个例外?
how can I resolve this exception?
谢谢!
推荐答案
您需要的dom4j,这就是异常告诉你。
You need dom4j, that's what the exception is telling you
您可能想看看的POI网站列出的依赖上页的组件
此外,因为你有一个文件
,开放直接的是,不要通过的InputStream
去。有上在的Apache POI常见问题解答一节,基本上都采用一个文件更快和更低的内存比通过流缓冲整个事情!
Also, since you have a File
, open directly with that, don't go via an InputStream
. There's a section in the Apache POI FAQ on that, basically using a file is quicker and lower memory than buffering the whole thing via a stream!
这篇关于如何打开的.xlsx与POI SS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!