php PHPExcel 阅读器日期格式问题 - rangeToArray
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18867919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPExcel Reader Date Format Issue - rangeToArray
提问by Shafeeque
I am facing a Date format issue when reading excel using PHPExcel.
Even I used $objReader->setReadDataOnly(false);
getting format of the cell but not working for me.
This how I am reading the data from Excel.
使用 PHPExcel 读取 excel 时,我面临日期格式问题。甚至我使用了$objReader->setReadDataOnly(false);
获取单元格的格式但对我不起作用。这就是我从 Excel 读取数据的方式。
$get_excel_data = $objPHPExcel->getActiveSheet()->rangeToArray("A1:".$highestColumn.$highestRow);
When I am trying to print date, it shows like 03/06/13, and I have tried to convert in mysl date format using
当我尝试打印日期时,它显示为 03/06/13,并且我尝试使用 mysl 日期格式进行转换
date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($val[1])); // echoing 2036-03-06
But it is not working, Can anyone guide me to the issue ? The main problem is I am not getting the date as number format ( Excel ), Instead of it showing date as 03/06/13,
但它不起作用,谁能指导我解决这个问题?主要问题是我没有将日期作为数字格式( Excel ),而不是将日期显示为 03/06/13,
回答by Shafeeque
I have solved the date issue
我已经解决了日期问题
$get_excel_data = $objPHPExcel->getActiveSheet()->rangeToArray("A1:".$highestColumn.$highestRow);
$i = 1;
foreach($get_excel_data as $val) {
// in my case 2nd column will be date so that I can get the format by
$date = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCellByColumnAndRow(1, $i)->getValue())); // array index 1
}
回答by Glavi?
If PHPExcel_Shared_Date::ExcelToPHP($val[1]);
returns 03/06/13
, then this should work :
如果PHPExcel_Shared_Date::ExcelToPHP($val[1]);
返回03/06/13
,那么这应该有效:
$date = new DateTime(PHPExcel_Shared_Date::ExcelToPHP($val[1]));
echo $date->format('Y-m-d');
or
或者
echo date('Y-m-d', strtotime(PHPExcel_Shared_Date::ExcelToPHP($val[1])));