使用POI最新版本时遇到一些版本重构带来的小问题,纪录下:
问题一:
在使用poi-3.15-beta2版本解析excel时, 发现并有网友所说的WorkbookFactory类.
原因
从poi-3.7.jar开始, WorkbookFactory类已经放进poi-ooxml-XXX.jar中了.
解决方法
同时引入这两个jar包: poi-3.15-beta2.jar, poi-ooxml-3.15-beta2.jar
问题二:异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:181) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:140) at com.soosmart.util.ApachePOIUtils.getExcelColumnValue(ApachePOIUtils.java:26) at com.soosmart.util.ApachePOIUtils.main(ApachePOIUtils.java:49) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 4 more
原因及解决办法:
加入xmlbeans.jar
问题三:异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:181) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:140) at com.soosmart.util.ApachePOIUtils.getExcelColumnValue(ApachePOIUtils.java:26) at com.soosmart.util.ApachePOIUtils.main(ApachePOIUtils.java:49) Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 4 more
原因及解决办法:
加入commons-collections.jar
问题四:异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/drawingml/x2006/main/ThemeDocument at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2446) at java.lang.Class.getConstructor0(Class.java:2756) at java.lang.Class.getDeclaredConstructor(Class.java:2021) at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:55) at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:58) at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:625) at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:186) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:260) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:181) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:140) at com.soosmart.util.ApachePOIUtils.getExcelColumnValue(ApachePOIUtils.java:26) at com.soosmart.util.ApachePOIUtils.main(ApachePOIUtils.java:49) Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 13 more
原因和解决办法:
加入poi-ooxml-schemas.jar