PHPexcel 判断日期类型

若已经确定某列为日期型数据:

 for($currentRow=2;$currentRow <= $allRow;$currentRow++){
//从哪列开始,A表示第一列
for($currentColumn='A';$currentColumn <= $allColumn;$currentColumn++){
//数据坐标
$address=$currentColumn.$currentRow;
if($currentColumn =='E'){
$cvalue = gmdate("Y-m-d H:i:s", \PHPExcel_Shared_Date::ExcelToPHP($PHPExcel->getActiveSheet()->getCell($address)->getValue())); }
else{
$cvalue = $currentSheet->getCell($address)->getValue();
} $arr[$currentRow][$currentColumn]=$cvalue;
} }

若先判断,再设置

  for($currentRow=1;$currentRow<=$allRow;$currentRow++){
//从哪列开始,A表示第一列
for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
//数据坐标
$address=$currentColumn.$currentRow;
$cell = $currentSheet->getCell($address);
$cvalue = $cell->getValue(); if($cell->getDataType()==\PHPExcel_Cell_DataType::TYPE_NUMERIC){
$cellstyleformat = $cell->getStyle($cell->getCoordinate())
->getNumberFormat(); $formatcode = $cellstyleformat->getFormatCode(); if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $formatcode)) {
$cvalue = gmdate("Y-m-d", \PHPExcel_Shared_Date::ExcelToPHP($cvalue));
}
else{
$cvalue=\PHPExcel_Style_NumberFormat::toFormattedString($cvalue,$formatcode);
}
} //读取到的数据,保存到数组$arr中\
$arr[$currentRow][$currentColumn]=$cvalue;
}
}
上一篇:一种H.264高清视频的无参考视频质量评价算法(基于QP和跳过宏块数)


下一篇:多媒体开发之sps---解析sps得到图像的宽高