PHPExcel导入Excel文件,对Excel中日期单元格处置惩罚
/** * 推断字符串是不是是日期花样 * @param $date * @param $format * @return bool */ function is_date($date, $format = 'Y-m-d') { if (!$date || $date == '0000-00-00') return false; $unix_time_1 = strtotime($date); if (!is_numeric($unix_time_1)) return false; //非数字花样 $format_date = date($format, $unix_time_1); $unix_time_2 = strtotime($format_date); return ($unix_time_1 == $unix_time_2); } /** * excel数据导入 日期花样化 * @param $date * @return false|string */ function get_date_by_excel($date) { if (!$date || $date == '0000-00-00') return null; $unix_time = \PHPExcel_Shared_Date::ExcelToPHP($date); return ($unix_time < 0) ? date('Y-m-d', $unix_time) : date('Y-m-d', strtotime(gmdate('Y-m-d', $unix_time))); } /** * 猎取excel日期花样化效果 * @param $date string excel日期单元格字符串 * @param $default string $date未非日期时返回默许日期 * @return string */ function excel_date_format($date, $default = '') { if ($default == '') $default = date('Y-m-d'); if (is_date($date)) return $date; return get_date_by_excel($date) ?: $default; }
以上就是PHPExcel导入Excel文件并对其日期单元格处置惩罚的代码示例的细致内容,更多请关注ki4网别的相干文章!