PHPExcel读取excel表格时间单元格(转载)
error_reporting(E_ALL); date_default_timezone_set('Asia/shanghai'); /** PHPExcel_IOFactory */ require_once '../Classes/PHPExcel/IOFactory.php'; $inputFileName = '6081076641077444758.xls'; $objReader = new PHPExcel_Reader_Excel5(); $objPHPExcel = $objReader->load($inputFileName); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 $tempArray = array(); for($j=2;$j<=$highestRow;$j++){ for($k='A';$k<=$highestColumn;$k++){ if($k=='M'||$k=='O') //M列和O列是时间 $tempArray[] = excelTime($objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue()); else $tempArray[] = $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue(); } print_r($tempArray); unset($tempArray); } function excelTime($date, $time = false) { if(function_exists('GregorianToJD')){ if (is_numeric( $date )) { $jd = GregorianToJD( 1, 1, 1970 ); $gregorian = JDToGregorian( $jd + intval ( $date ) - 25569 ); $date = explode( '/', $gregorian ); $date_str = str_pad( $date [2], 4, '0', STR_PAD_LEFT ) ."-". str_pad( $date [0], 2, '0', STR_PAD_LEFT ) ."-". str_pad( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : ''); return $date_str; } }else{ $date=$date>25568?$date+1:25569; /*There was a bug if Converting date before 1-1-1970 (tstamp 0)*/ $ofs=(70 * 365 + 17+2) * 86400; $date = date("Y-m-d",($date * 86400) - $ofs).($time ? " 00:00:00" : ''); } return $date; }
转自:https://www.cnblogs.com/wuheng1991/p/6807059.html
无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。