I have found out the solution:
Method _formatAsDate in the file PHPExcel/Style/NumberFormat.php
if the date is like 16/11/2014, when passed to strtotime will result in false as the date is supposed to be in format m/d/Y by strtotime. So if you change the format to m/d/Y if it's d/m/Y then the solution will always be correct.
Earlier:
- 16/11/2014==1970-01-01 (Row: 1)
- 16/11/2014==1970-01-01 (Row: 2)
- 23/12/2014==1970-01-01 (Row: 3).
Now:
- 11/16/2014==2014-11-16 (Row: 1)
- 11/16/2014==2014-11-16 (Row: 2)
- 12/23/2014==2014-12-23 (Row: 3)
Code is still the same and simple to import the file:
protected function importExcel($filePath) {
$excelData = array();
if ($filePath) {
$objPHPExcel = PHPExcel_IOFactory::load($filePath);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
$data = array();
for ($row = 1; $row <= $highestRow; ++$row) {
$values = array();
for ($col = 0; $col < $highestColumnIndex; ++$col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
if (isset($val) && $val)
$data[$row][$col] = $val;
}
}
$excelData[$worksheetTitle] = $data;
}
return $excelData;
}
return FALSE;
}