iliaal / php_excel

PHP Extension interface to the Excel writing/reading library
http://ilia.ws
533 stars 131 forks source link

Can't get a working date #260

Closed BenLeroy closed 4 years ago

BenLeroy commented 4 years ago

Hello,

I'm trying to display a specific date format in xlsx:

Here's code sample inspired from https://github.com/iliaal/php_excel/issues/47 :

$oBook = new ExcelBook($log,$key,true);
$oBook->setLocale('fr_FR.UTF-8');
$oBook->addSheet('sheet_1');
$oSheet = $oBook->getSheet(0);
$my_format = $oBook->addCustomFormat('dd/mm/yyyy hh:mm:ss'); // also tried with 'MM' and 'HH'
$formatDate = $oBook->addFormat();
$formatDate->numberFormat($my_format);
....
$eventDate = new DateTime($row['event_date_start']); // <- date from mysql (Y-m-d H:i:s)
$oSheet->write($y, $x, $eventDate->format('d/m/Y H:i:s'), $formatDate); //-> not written
=> $oSheet->write($y, $x++, $eventDate->format('d/m/Y H:i:s'), $formatDate);
// or
$oSheet->write($y, $x, $eventDate->getTimeStamp(), $formatDate); //-> not written
$oSheet->write($y, $x++, $eventDate->getTimeStamp(), $formatDate); 

What am i doing wrong?

Never forget to increment your column....