KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Format date on ColumnMeta error #1626

Closed Daniel Cordeiro opened this topic on on Sep 21, 2020 - 7 comments

Daniel Cordeiro commented on Sep 21, 2020

Hi,

have created spreadsheets using ColumnMeta, but when I try to form dates, nothing happens

The datacolumn in PostgreSql database is timestamp.

David Winterburn commented on Sep 22, 2020

Hi Daniel,

For date/datetime columns, please use "displayFormat" to display its value in that format. The "format" meta is used to instruct report to understand the date column's values in which format. Here's an example:

    ->pipe(new ColumnMeta(array(
        "column_1" => array(
            "format" => "Y-m-d H:i:s", //i.e date value from datasource has format like "2020-09-22 00:00:00"
            "displayFormat" => "d/m/Y", //we want to show this column as "22/09/2020" in the report
        )
    )))

Let us know how it works for you. Thanks!

Daniel Cordeiro commented on Sep 22, 2020

Unfortaly, this options works only when I put into view. If I using in ColumnData to create a xlsx file returned this error bellow:

Daniel Cordeiro commented on Sep 22, 2020

Its strange... When I open in LibreOffice 7 the column show me this error. But when open in Excel 365 or Gnumeric The column its correct.

David Winterburn commented on Sep 23, 2020

Please try other "displayFormat" values (e.g "d-m-Y", "Y/m/d", etc) to see how LibreOffice 7 works. Thanks!

Daniel Cordeiro commented on Sep 24, 2020

It's work from exportToExcel, but to export with exportToXLSX not. Apparently ColumnMeta is not considered for exportToXLSX

David Winterburn commented on Sep 25, 2020

Hi Daniel,

Unfortunately at the moment the library used by exportToXLSX is somewhat limited with formatting cell because all cell values are inserted as general values. If you must use exportToXLSX, which is faster and supports exportint huge files, instead of exportToExcel, which is more flexible, I would suggest formatting the values before saving them to datastore like this:

    ->pipe(new \koolreport\processes\Map(array(
        "{value}" => function($row) {
            $row["formattedDate1"] = myFormatDateFunc($row["date1"]); //use php code to change your date format to a new one, says Y-m-d to d/m/Y
            return $row;
        )
    )))
    ->pipe($this->dataStore("myDS")):      

Then use the formatted column "formattedDate1" in your export function.

Daniel Cordeiro commented on Sep 25, 2020

I will try this, Thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

Export