简体   繁体   中英

i m trying to convert xlsx to csv but i m getting this exception

Exception in thread "main" org.apache.poi.POIXMLException: ]

java.lang.reflect.InvocationTargetException
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:61)
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:277)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:186)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:189)
    at com.simplecode.excel.XlstoCSV.xls(XlstoCSV.java:26)
    at com.simplecode.excel.XlstoCSV.main(XlstoCSV.java:86)

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59)

... 5 more

Caused by: java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
    at java.lang.Class.getMethod0(Class.java:2642)
    at java.lang.Class.getMethod(Class.java:1579)
    at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:174)
    at org.apache.xmlbeans.XmlBeans.buildNodeMethod(XmlBeans.java:195)
    at org.apache.xmlbeans.XmlBeans.buildNodeToCursorMethod(XmlBeans.java:232)
    at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:131)
    at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:39)

You are missing to include the javax.xml.stream.jar file.

Download from here

This problem can be solved using the same Apache POI (- the Java API for Microsoft Documents) version jars just simply add jars of same version
Ex- Respective jars solved conversion from

  1. xls-to csv and
  2. xlsx-to csv and

Jar List-

  1. poi-3.9.jar
  2. poi-ooxml-3.9.jar
  3. poi-ooxml-schemas-3.9.jar
  4. xmlbeans-2.3.0.jar

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