我试图将xlsx转换为csv,但我得到了这个例外

时间:2014-12-09 11:51:13

标签: java

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)

2 个答案:

答案 0 :(得分:2)

您缺少包含javax.xml.stream.jar文件。

Download from here

答案 1 :(得分:-1)

使用相同的Apache POI(Microsoft文档的Java API)版本的jar即可解决此问题,只需添加相同版本的jar
各个罐子解决了

的转换问题
  1. xls-to csv和
  2. xlsx-to csv和

枪手列表-

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