使用POI读取由excel公式生成单元格数据

需求:读取这里面的数字3orm

 

实现:get

    public String getCellValue(HSSFCell cell) {
        String value = null;
        if (cell != null) {
            switch (cell.getCellType()) {
            case HSSFCell.CELL_TYPE_FORMULA:
                // cell.getCellFormula();
                try {
                    value = String.valueOf(cell.getNumericCellValue());
                } catch (IllegalStateException e) {
                    value = String.valueOf(cell.getRichStringCellValue());
                }
                break;
            case HSSFCell.CELL_TYPE_NUMERIC:
                value = String.valueOf(cell.getNumericCellValue());
                break;
            case HSSFCell.CELL_TYPE_STRING:
                value = String.valueOf(cell.getRichStringCellValue());
                break;
            }
        }it

        return switchNumeric(value);
    }io


    
       public static String switchNumeric(String str){ 
            if(str.indexOf(".")>0){  
                str = str.replaceAll("0+?$", "").replaceAll("[.]$", "");;  
            }  
            return str;  
        }  im