欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

poi 对cell的数值转换

程序员文章站 2024-02-24 13:40:19
...

注意数值型转换:

private static String getCellValue(Cell c) {
        String o = null;
        switch (c.getCellType()) {
        case Cell.CELL_TYPE_BLANK:
            o = "";
            break;
        case Cell.CELL_TYPE_BOOLEAN:
            o = String.valueOf(c.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_FORMULA:
            o = String.valueOf(c.getCellFormula());
            break;
        case Cell.CELL_TYPE_NUMERIC:
            if (HSSFDateUtil.isCellDateFormatted(c)) {
                double d = c.getNumericCellValue();
                Date date = HSSFDateUtil.getJavaDate(d);
                SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd");
                o = dformat.format(date);
            }
            else {
                NumberFormat nf = NumberFormat.getInstance();
                nf.setGroupingUsed(false);// true时的格式:1,234,567,890
                o = nf.format(c.getNumericCellValue());//
            }
            break;
        case Cell.CELL_TYPE_STRING:
            o = c.getStringCellValue();
            break;
        default:
            o = null;
            break;
        }
        return o;
    }