$sheet -> getCell(‘A1’) -> getValue()
If the value is a “date”, then this statement will get a “number”.
To convert this number for PHP to use:
1 2 3 4 5 6 7 8 9 10 |
//This way will cause incorrect result because of unknown reason $birth = $sheet->getCellByColumnAndRow(1, $row)->getValue(); //PHPExcel will read as GMT+0 $birth = PHPExcel_Shared_Date::ExcelToPHP( $birth ); //If PHP timezone is UTC+0 echo var_dump(date('Y-m-d', $birth)); //If PHP timezone is not UTC+0 echo var_dump(gmdate('Y-m-d', $birth)); |
1 2 3 |
//This way create a formatted string directly $birth = $sheet->getCellByColumnAndRow(1, $row)->getValue(); $birth = PHPExcel_Style_NumberFormat::toFormattedString($birth, "YYYY-M-D"); |
1 2 3 |
//Get time value only $cell = $sheet->getCellByColumnAndRow($i, $row_index); $value = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'hh:mm:ss'); |
Reference: