I’m trying to write an excel file from php, and I need that some cells to have date type; do you have any ideas which is the format code for that type of cell?
I’m using the code from http://pizzaseo.com/php-excel-creator-class to generate the excel files.
Thanks.
Your question is a little vague, and I know little about PHP, but I’m the maintainer of a similar Python package … so here’s an attempt to help:
Excel doesn’t differentiate at the BIFF record level between numbers and dates. The only way that an XLS reader can tell whether a date was intended by the writer is to parse the “number format” that the writer associated (indirectly) with the cell in question.
I presume that you are using this Format function to set the num_format of what the package calls a “format” (which includes not only “number format” but alignment, background, borders, …):
$num_format should be an Excel “number format” (e.g. for a money amount you might use “$0.00”). For a date you just use whichever you prefer of the standard date formats Excel provides, or you could use a customised format like “yyyy-mm-dd hh:mm:ss” (handy when debugging).
Then you do:
Where $format is as described above. For a date, $value should be a floating point day-number where 1900-03-01T00:00:00 is represented as day-number 61.0 and you should avoid earlier dates because … [long rant omitted], and if there’s a “datemode” or “1904” option available, ensure that you are using the (should be default) 0 or False or “no, thanks” option.