Java中excel表格导入数据库

来源:互联网 发布:淘宝网宽松牛仔裤女款 编辑:程序博客网 时间:2024/06/05 14:26

java使用poi包完成将excel数据的读写

注意事项:
1. excel中单元格格式和mysql数据库中字段类型的相互转换
判断excel中单元格中数据的类型

Object cellValue = null;//cellValue的值switch (cell.getCellType()) {    case Cell.CELL_TYPE_STRING:        System.out.println(cell.getRichStringCellValue().getString());        cellValue = cell.getRichStringCellValue().getString();        break;    case Cell.CELL_TYPE_NUMERIC:        if (DateUtil.isCellDateFormatted(cell)) {            System.out.println(cell.getDateCellValue());            cellValue= cell.getDateCellValue();            //TODO 可以按日期格式转换            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");             String time = formatter.format(cellValue);            System.out.println("formater time:"+time);            }else{             System.out.println(cell.getNumericCellValue());        }        break;                                             case Cell.CELL_TYPE_BOOLEAN:        System.out.println(cell.getBooleanCellValue());        cellValue = cell.getBooleanCellValue();        break;    case Cell.CELL_TYPE_FORMULA:        System.out.println(cell.getCellFormula());        cellValue = cell.getCellFormula();        break;    default:        System.out.println("not find match type.");}
0 0
原创粉丝点击