导入这块。有个问题问问大家。现在出现的情况是:导入必须先保存下才能导 。我试着换了poi的版本。发现
cell = row.getCell((short) 1); 这个已经作废了
看了下API也没找到更好方法。看看能帮我想想方法吗?应该怎么写

解决方案 »

  1.   

    cell = row.getCell((short) 1);变成cell = row.getCell(1); 了 不需要强转成short型了,不知LZ用的版本是不是这个样子
      

  2.   

    en.pudnet.com
      

  3.   

    按楼上的 改了以后 结果抛出异常
    org.apache.poi.hssf.usermodel.HSSFRow.getCell(I)Lorg/apache/poi/hssf/usermodel/HSSFCell;
    ERROR [org.apache.struts.actions.DispatchAction] - <Dispatch[/standard] to metho
    d 'readExcel' returned an exception>
    java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
      

  4.   

    我的jar包  是 poi3.2
      

  5.   


    cell = row.getCell((short) 1);变成cell = row.getCell(1); 了 不需要强转成short型了,POI3.2版本这个取得cell的函数已经不用在转换成short了,直接就是一个整型。
    你出现异常的的那个HSSFRow.getCell(I)是要循环取得变量?? 你先直接写1,不要写变量,试验下。正常来说应该没问题的,我就是用POI3.2写的,没有问题,你跟踪代码看看具体是那行的错误就清楚了。
    我的部分代码如下:

    /*判断完基本的容错信息后,就开始读取存储导入的信息了*/
         String teamName = "";
         String teamerName = "";
         String re = "";
         String teamNameTemp = "";
        
         for (int i = firstNum + 1; i <= lastNum; i++) {
    // 跳过第一行的标题
    HSSFRow row = sheet.getRow(i);
    // 如果出现空行,则跳过 ,直接读取下一行
    if (row == null){
    continue;
    }
    HSSFCell cell = null;
    HSSFCell tempCell = null;
    ComQueryManagerVO tempVo = new ComQueryManagerVO(); cell = row.getCell(1);
    teamerName = cell.toString().trim();
    tempVo.setTeamerName(teamerName);

    cell = row.getCell(2);
    re = cell.toString().trim();
    tempVo.setRe(re);

    cell = row.getCell(0);
    teamName = cell.toString().trim();

    //判断球队的名字不能相同
    for(int j = i+1; j <= lastNum; j++){
    HSSFRow rowConp = sheet.getRow(j);
    if (rowConp == null){
    continue;
    }
    tempCell = rowConp.getCell(0);
    teamNameTemp = tempCell.toString().trim();
    if(teamNameTemp.equals(teamName)){
    errorCellConp += ("(" + (i) + ",A)")
    + ("(" + (j + 1) + ",A)"); }

    }
    if (errorCellConp.length() > 1) {

     System.out.println("该单元格的字段不容许重复"+errorCellConp);
     errorCellConp = "单元格读数据错误:坐标" + errorCellConp;
    throw new ServiceException("该单元格的字段不容许重复");
    }
    tempVo.setTeamName(teamName);
    reInfoList.add(tempVo);
         }
         return reInfoList;
        }
      

  6.   

    谢谢 刚解决  原来我在WEB-INF\lib 的那个低版本没有删 只删了工程的那个低版本。 这样在读的时候 出错了