1. 程式人生 > >Java中excel表格匯入資料庫

Java中excel表格匯入資料庫

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."); }