Cannot get a STRING value from a NUMERIC cell

Cannot get a STRING value from a NUMERIC cell
错误一:
导入Excel表格数据,该列设置数据类型为String,输入数据是int类型
解决方法:cell.setCellType(CellType.STRING);
错误二:日期类型需要定义格式
解决方法如下:
 

 protected Object getCellFormatValue(Cell cell) {
        Object val = "";
        if (null != cell) {
            if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA)
            {
                val = cell.getNumericCellValue();
                if (DateUtil.isCellDateFormatted(cell))
                {
                    val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
                }
                else
                {
                    if ((Double) val % 1 != 0)
                    {
                        val = new BigDecimal(val.toString());
                    }
                    else
                    {
                        val = new DecimalFormat("0").format(val);
                    }
                }
            }
            else if (cell.getCellType() == CellType.STRING)
            {
                val = cell.getStringCellValue();
            }
            else if (cell.getCellType() == CellType.BOOLEAN)
            {
                val = cell.getBooleanCellValue();
            }
            else if (cell.getCellType() == CellType.ERROR)
            {
                val = cell.getErrorCellValue();
            }
        } else {
            val = "";
        }
        return val;
    }

-------------------------------------以下无正文-----------------------------------------------------------

注:仅供学习,记录问题和参考,共勉!

你可能感兴趣的:(java,开发语言)