poi解析Excel时类型的判断与数字的转换

来源:互联网 发布:egd网络黄金跑路了 编辑:程序博客网 时间:2024/06/07 02:31
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
    double d = cell.getNumericCellValue();
   
    if (d - (int) d < Double.MIN_VALUE) { 
        // 是否为int型
    cellStr = Integer.toString((int) d);
        } else{
       DecimalFormat df = new DecimalFormat("0");  
        
        cellStr = df.format(cell.getNumericCellValue());
        
        
        }
   
 
    }else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
    cellStr = cell.getRichStringCellValue().getString();
   
    }else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
    cellStr = cell.getCellFormula();
    }else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
    cellStr = " ";
    }else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
    cellStr = " ";
    }
0 0
原创粉丝点击