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