简体   繁体   中英

Read a xlsx file using apache poi in java? not working

I have used all poi jars but still i ame getting this error

Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62) at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456) at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:271) at ReadExcel.readXLSXFile(ReadExcel.java:38) at ReadExcel.main(ReadExcel.java:69) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) ... 5 more Caused by: java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader at org.openxmlfo rmats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source) at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:46) ... 10 more Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader 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) ... 12 more

Sounds like you do not have the correct dependencies in you project. POIXMLTypeLoader comes with POI 3.14-Beta1 and the ooxml-schemas:1.3 reference that class.You have the following options, you can add any of this dependency in your project:

  • use poi 3.14 beta1

     <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> 
  • use ooxml-schemas 1.2

     <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.14</version> </dependency> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM