excel导入 手机号数据格式不对处理,日期问题
public Object getCellValue(Row row, int column){
Object val = "";
try{
Cell cell = row.getCell(column);
if (cell != null){
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
//判断是否为日期类型
if(HSSFDateUtil.isCellDateFormatted(cell)){
//用于转化为日期格式
Date d = cell.getDateCellValue();
DateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
val = formater.format(d);
}else{
// 用于格式化数字,只保留数字的整数部分
/*DecimalFormat df = new DecimalFormat("#");//转换成整型
val = df.format(cell.getNumericCellValue());*/
//cell.getNumericCellValue();
cell.setCellType(1);
val = cell.getStringCellValue() + "";
}
}else if (cell.getCellType() == Cell.CELL_TYPE_STRING){
val = cell.getStringCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA){
val = cell.getCellFormula();
}else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){
val = cell.getBooleanCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_ERROR){
val = cell.getErrorCellValue();
}
}
}catch (Exception e) {
return val;
}
return val;
}