How to pre-format a cell to date on Laravel Excel

Jay Marz picture Jay Marz · Apr 24, 2015 · Viewed 18.6k times · Source

I am using the package maatwebsite.com/excel for exporting xls files from my app. I want to pre-format the cell to date. Is it possible?

I have formatted the data to date, but I want that the cell would be pre-formatted with date (its default cell format is general). How can I achieve this in PHP or Laravel 4?

Answer

haakym picture haakym · Apr 24, 2015

Have you tried this yet?

$sheet->setColumnFormat(array(
    'A' => 'yyyy-mm-dd'
));

From the documentation: http://www.maatwebsite.nl/laravel-excel/docs/export#format

Different date formats are available here: http://www.maatwebsite.nl/laravel-excel/docs/reference-guide#formatting