Open ignatenkovnikita opened 8 years ago
I find solution File basic\Attribute modify method replaceValue after
$value = $this->cell->getValue();
add row ot check if value is date
if(PHPExcel_Shared_Date::isDateTime($this->cell)) {
$value = PHPExcel_Shared_Date::ExcelToPHP($value);
}
I handled it with helper method:
use DateTime;
use PHPExcel_Shared_Date;
/**
* @param $excelDateTime
* @return string
*/
protected static function convertDateTime($excelDateTime)
{
$dateTime = (new DateTime)->setTimestamp(PHPExcel_Shared_Date::ExcelToPHP($excelDateTime));
return $dateTime->modify("- {$dateTime->getOffset()} seconds")->format('Y-m-d H:i');
}
Then in standardAttributesConfig
I just call it like that:
[
'name' => 'available_from',
'valueReplacement' => function ($value) {
return self::convertDateTime($value);
},
],
But yes, it will be better if an extension provides better abstracton for that. Will think how to add this feature.
If value in cell "30.09.2015", i get value "42277", beacause format cell is date. How detect date format?