2016-09-23 1 views
1

PHPExcel mir Wert unterschiedliche Datumsformate auf demselben Blatt VorlageKonvertieren von PHP Zelle Wert bis heute

Dies ist der Code geben verwende ich

$value = $this->worksheet->getCellByColumnAndRow(11, 1) ->getFormattedValue(); 
$this->_date = DateTime::createFromFormat("j/n/Y",$value); 

Ich habe folgende Antworten versucht, aber sie taten es nicht lösen sie

PHPEXCEL get formatted date as is visible in excel file

how to get date from excel using PHPExcel library

Dies ist ein Problem, dem ich begegnet bin und ich hoffe, ich kann jemand anderem helfen, der dieses Problem auch hat.

Antwort

1

Sie können einen Excel serialisiert Zeitstempel-Wert direkt zu einem Objekt PHP Datetime konvertieren, ohne dass eine formatierte Zeichenfolge, erstellen und dann ein neues Datetime-Objekt aus, dass erstellen:

$msExcelSerializedTimestampValue = $this->worksheet 
    ->getCellByColumnAndRow(11, 1) 
    ->getCalculatedValue(); // getValue() is even easier if the cell doesn't contain a formula 
$this->_date = PHPExcel_Shared_Date::ExcelToPHPObject($msExcelSerializedTimestampValue); 
0

Dies löste es für mich

$value = $this->worksheet->getCellByColumnAndRow(11, 1) ->getCalculatedValue(); 
$timeValue = (string)PHPExcel_Style_NumberFormat::toFormattedString($value,PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); 
$this->_date = DateTime::createFromFormat("Y-m-d",$timeValue);