zwh19338 2010-03-19 16:11
浏览 312
已采纳

poi读取excel2007中的数据

package test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class readerEXCEL {

/**
 * @param args
 */
public   static   String   fileToBeRead="D:\\123.xlsx";
public static void main(String[] args) {

    XSSFWorkbook workbook;
 try {
    workbook = new XSSFWorkbook(new FileInputStream(fileToBeRead));
    XSSFSheet sheet = workbook.getSheetAt(0);
    for(int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum();i++){
        XSSFRow   row = sheet.getRow(i);
       for(int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++ ){
        System.out.print(row.getCell(j)+"\t");
        }
         System.out.println("");
       }
    } catch (FileNotFoundException e) {

            e.printStackTrace();
    } catch (IOException e) {

    e.printStackTrace();
   }    
}       

}

运行之后,报错:
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:256)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:196)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:179)
at test.readerEXCEL.main(readerEXCEL.java:23)
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:494)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59)
... 4 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2365)
at java.lang.Class.getMethod0(Class.java:2611)
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.(XmlBeans.java:131)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:102)
at org.apache.poi.xssf.model.StylesTable.(StylesTable.java:91)
... 9 more

这是什么错呀,我刚接触这些,不太懂

  • 写回答

2条回答 默认 最新

  • wanghaolovezlq 2010-03-19 16:18
    关注

    少了这个jar包 jsr173_1.0_api.jar

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换