对Apache POI的使用
public static void main(String[] args) throws IOException {Workbook wb = new XSSFWorkbook();OutputStream output = new FileOutputStream("test.xlsx");Sheet s = wb.createSheet("测试表单");Row r = s.createRow(0);r.createCell(0).setCellValue("数据");wb.write(output);output.close();}
?读取微软或者其他办公工具产生的文档需要配置POI,POI的下载地址
http://poi.apache.org/
其中,在读取2007版本以上的EXCEL需要用到POI中的XSSFWorkbook类。
但是在用的过程中,我发现会报错:
java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
百度后,发现有人提示是少xbean.jar,下载地址:
http://xmlbeans.apache.org/
加载后,继续报错:
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
百度后,发现少dom4j.jar,下载地址:
http://www.dom4j.org/dom4j-1.6.1/
终于加全了,运行,好了。
附件里有我整合的时候用到的包,有可能有不必要的,有时间了再精简。
?
?