iliaal / php_excel

PHP Extension interface to the Excel writing/reading library

Home Page:http://ilia.ws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get a working date

BenLeroy opened this issue · comments

commented

Hello,

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

  • example on github main page doesn't work for me
$date = new \DateTime('2014-08-02');
$dateFormat = new \ExcelFormat($xlBook);
$dateFormat->numberFormat(\ExcelFormat::NUMFORMAT_DATE);
$xlSheet2->write($row, $col, $date->getTimestamp(), $dateFormat, \ExcelFormat::AS_DATE);
  • I want to write date like dd/mm/yyyy hh:mm:ss

Here's code sample inspired from #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....