POI 身份证号码 手机号 日期值的处理方式

时间:2023-01-14 14:33:50
 private static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  

 /**
* 获取单元格的值
*
* @param cell
* @return
*/
public static String getCellValue(Cell cell) {
DecimalFormat df = new DecimalFormat("#");
if (cell == null)
return ""; if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
return cell.getStringCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
return cell.getCellFormula();
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
if (HSSFDateUtil.isCellDateFormatted(cell)) { //判断是日期类型
Date dt = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());//获取成DATE类型
return dateformat.format(dt);
}else{ //转化电话号码和身份证号码为字符串
return String.valueOf(df.format(cell.getNumericCellValue()));
} }
return "";
}