今天写了个excel操作类,在操作excel2007时报了个异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at org.com.java.micro.util.ExcelUtil.readExcelFile2007(ExcelUtil.java:70)
at org.com.java.micro.util.ExcelUtil.readExcelFile(ExcelUtil.java:47)
at org.com.java.micro.util.ExcelUtil.main(ExcelUtil.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
这个错误是由于POI包是默认不支持excel2007操作的,要加入一个xmlbeans的包xbean.jar,加入后再运行又报了个异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTSheet
at org.com.java.micro.util.ExcelUtil.readExcelFile2007(ExcelUtil.java:70)
at org.com.java.micro.util.ExcelUtil.readExcelFile(ExcelUtil.java:47)
at org.com.java.micro.util.ExcelUtil.main(ExcelUtil.java:28)
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 3 more
这个异常是由于poi不支持解析excel2007,要加入POI的一个解析包poi-ooxml-schemas-3.9-20121203.jar,后面的数字是版本,加入后还得加入一个dom4j-1.6.1.jar包,即可正常运行
我自己整理了下 下用POI操作excel的所需要加入的包: