phpexcel读取excel时间的坑

按照phpexcle的api,将excle解析为数组的代码:
$this->excel = PHPExcel_IOFactory::load($this->file_path);
$sheetData = $this->excel->getActiveSheet()->toArray(null,true,true,true);


如果字段有日期格式,比如2014-06-28 23:12:08,解析出来的数组对应的日期字段有问题,百度了下各种解决办法,以下最方便。
$this->excel = PHPExcel_IOFactory::load($this->file_path);
$ActiveSheet=$this->excel->getActiveSheet();
$ActiveSheet->getStyle('G')->getNumberFormat()->setFormatCode('yyyy-mm-dd h:i');
$sheetData = $ActiveSheet->toArray(null,true,true,true);

如果excle文件列是动态的话,就只能循环列,内容用正则来判断。

你可能感兴趣的:(phpexcel)