Using PHPExcel, I a trying to fetch data from Excel file and save it in MySql database using the following code:
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$i=0;
$arr =array("","","","","","","");
for ($row = 1; $row <= $highestRow; $row++)
{
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
foreach($rowData[0] as $k=>$v)
{
if(PHPExcel_Shared_Date::isDateTime($v))
{
$arr[$i] = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($InvDate));
}
else
$arr[$i] = $v;
$i++;
}
This code gives following error:
Catchable fatal error: Argument 1 passed to PHPExcel_Shared_Date::isDateTime() must be an instance of PHPExcel_Cell, double given, called in ............
When I read columns as follows:
foreach($rowData[0] as $k=>$v)
{
$arr[$i] = $v;
$i++;
}
The date columns are read as normal text even if I set Cell Formatting to date in excel. In all, i have 3 date columns in each record of my excel file which may either have a date or will be blank.
The date column of excel has dates in format: d-m-Y. I want it to be fetch in the format: 'Y-m-d' if possible otherwise i will have to explode it and convert it manually. The date will be finally stored into mysql Date type column.
I read several articles at stackoverflow too, but couldn't get the perfect solution.