用POI导入数据库时,出现java.lang.IllegalStateException: Cannot get a text value from a numeric cell的错误,帮忙解决下。

解决方案 »

  1.   

    你需要对类型进行判断,numeric型的不能用getStringCellValue()去读
    error when get numeric valueint cellType = cell.getCellType(); 
    if ( cellType == HSSFCell.CELL_TYPE_NUMERIC ) 

            fvalue = ( float ) cell.getNumericCellValue() ; 

    else if( cellType == HSSFCell.CELL_TYPE_STRING  ) 

                    
       try { 
            svalue = getStringCellValue( cell ) ; 
            svalue = getStringForDecimal ( svalue ) ; 
            fvalue = StringToDecimal( svalue ) ; 
       } 
       catch ( Exception e ) 
       { 
          fvalue = ( float ) cell.getNumericCellValue(); 
       }