PHPExcel读取Excel 时间
$info = pathinfo ( $path );
$ext = $info ['extension'];
$excelReader = null;
if ( $ext == 'xls' )
$excelReader = new PHPExcel_Reader_Excel5();
else
$excelReader = new PHPExcel_Reader_Excel2007();
$phpExcelInstance = $excelReader->load($path);
$sheet = $phpExcelInstance -> getSheet ( 0 );
$highestRow = $sheet->getHighestRow();
$highestColumm = $sheet->getHighestColumn();
$arr = array ();
for ( $row = 2 ; $row <= $highestRow ; $row ++ )
{
$cell = $sheet->getCellByColumnAndRow(0, $row);
$value = $cell->getValue();
$date_value = '';
if ($cell->getDataType()==PHPExcel_Cell_DataType::TYPE_NUMERIC)
{
$cellstyleformat=$cell->getStyle()->getNumberFormat();
$formatcode=$cellstyleformat->getFormatCode();
if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $formatcode))
{
$date_value = gmdate("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($value));
}
else
{
$date_value = PHPExcel_Style_NumberFormat::toFormattedString($value,$formatcode);
}
}
elseif($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_STRING)
{
$date = date_create($value);
if ($date)
{
$date_value = date_format($date,"Y-m-d");
}
else
{
$err_msg = "表格第".$row."行时间格式错误,请修改后再导入";
break;
}
}
else
{
$err_msg = "表格第".$row."行时间格式错误,请修改后再导入";
}
}
if($err_msg)
{
echo $err_msg;
exit;
}