PHPExcel
PHPExcel copied to clipboard
toArray(null, true, true) formatting dates incorrectly.
Although quite old, this exchange claims:
toArray(NULL,TRUE,TRUE);
will return all the cell values in the worksheet (calculated and formatted) exactly as they appear in Excel itself.
This appears to be false. Here are the steps.
Entering '2017-07-27' in Excel 2013 auto re-formats to '7/27/2017'. Run the following code on the file.
$xlreader = PHPExcel_IOFactory::createReader('Excel2007');
$xldoc = $xlreader->load($filename);
$xlsheet = $this->xldoc->getActiveSheet();
$xldata = $this->xlsheet->toArray(null, true, true);
Examining the date field value with var_dump
shows string '07-27-17' (length=8)
.
This is odd and unexpected, but the true problem is revealed when using PHP date handing, where dashes indicate a year-month-day pattern, rather than the American month-day-year pattern (which require slashes to be recognized).
With the previous example date, strtotime()
fails and returns false. Ambiguous dates are significantly more worrisome. For example, if I start with '2007-06-05' (June 5th 2007), I end with '2006-05-07' (May 7th 2006).
I had a same problem. Can you help to solve this problem?
I Have a same problem too