PHPExcel icon indicating copy to clipboard operation
PHPExcel copied to clipboard

toArray(null, true, true) formatting dates incorrectly.

Open bdjnk opened this issue 9 years ago • 2 comments

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).

bdjnk avatar Feb 18 '16 19:02 bdjnk

I had a same problem. Can you help to solve this problem?

agiratech-mani avatar Jun 20 '16 14:06 agiratech-mani

I Have a same problem too

fazalsandhi avatar Nov 16 '17 08:11 fazalsandhi