NutzCN Logo
短点 excel_e21fc892
发布于 2942天前 作者 明天会吹什么风 1164 次浏览 复制 上一个帖子 下一个帖子
标签:

查看完整内容

```protected static String getCellValue(Cell cell) {
String value = null;

    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_FORMULA: // 公式
        case Cell.CELL_TYPE_NUMERIC: // 数字

            double doubleVal = cell.getNumericCellValue();
            short format = cell.getCellStyle().getDataFormat();
            //String formatString = cell.getCellStyle().getDataFormatString();

            //System.out.println("index:"+cell.getColumnIndex()+" format:"+format+" value:"+doubleVal+" formatstr:"+cell.getCellStyle().getDataFormatString());

            if (format == 14 || format == 31 || format == 57 || format == 58 || format == 180 || format == 176) {
                // 日期
                Date date = DateUtil.getJavaDate(doubleVal);
                value = formatDate(date, dateFmtPattern);
            } else if (format == 20 || format == 32 || format == 181 || format == 179 ) {
                // 时间
                Date date = DateUtil.getJavaDate(doubleVal);
                value = formatDate(date, timeFmtPattern);
            } else {
                //判断小数点位数
                String valueStr = String.valueOf(doubleVal);
                valueStr = valueStr.substring(valueStr.indexOf(".")+1);
                if( valueStr.length() == 1 && valueStr.equals("0")){
                    value = String.valueOf((int)doubleVal);
                }else{
                    value = String.valueOf(doubleVal);
                }
            }

            break;
        case Cell.CELL_TYPE_STRING: // 字符串
            value = cell.getStringCellValue();
            break;
        case Cell.CELL_TYPE_BLANK: // 空白
            value = "";
            break;
        case Cell.CELL_TYPE_BOOLEAN: // Boolean
            value = String.valueOf(cell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_ERROR: // Error,返回错误码
            value = String.valueOf(cell.getErrorCellValue());
            break;
        default:
            value = "";
            break;
    }

    return value;
}```
0 回复
添加回复
请先登陆
回到顶部