KoolReport's Forum

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

Illegal offset type in isset or empty when I using template #1625

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

Daniel Cordeiro commented on Sep 21, 2020

I can save successfully a excel file when I declare only dataSource in view template. But, when I define the columns (to configure the format of the fields), this always show me the exception: Illegal offset type in isset or empty

Same problem if I use BigSpreadsheetExportable component.

Then koolreport pro version is a last release updated using compose update.

David Winterburn commented on Sep 21, 2020

Hi Daniel,

We've checked Excel package and confirmed that as of the latest release the Excel's Table widget is limited to not being able to set column's meta directly, i.e "columns" can only contain a list of column names:

    \koolreport\excel\Table::create(array(
        ...
        "columns" => ["Column_1", "Column_2", ...],
        ...
    ));

To set the column's meta properties like "label", "type" you would have to set them on the datastore before. For example, in a report's setup:

    //MyReport.php's setup()
    ...
    ->pipe(new ColumnMeta(array(
        "Column_1" => array(
            "label" => "Column 1"
        ),
    )))
    ->pipe($this->dataStore("myDs"));

or directly in an excel template:

    //MyReportExcel.view.php
    <?php
        $ds = $this->dataStore("myDs");
        $meta = $ds->meta();
        //Modify column meta
        $meta["columns"]["Column_1"] = [
            "label" => "Column 1"
        ];
        //Set modified meta back to datastore
        $ds->meta($meta);
        \koolreport\excel\Table::create(array(
            "dataSource" => $ds,
            "columns" => ["Column_1", "Column_2", ...],
            ...
        ));

Please try these approaches and let us if it works for you or not.

To save users from this hassle, the next version of Excel package is going to add support for setting column's meta directly in the Table widget. Thanks!

Daniel Cordeiro commented on Sep 21, 2020

Hello,

And how I set type proterties to columns? I want set soma columns to date and decimal number.

I saw ticket #763 with you show de table widget to format columns.

Best Regards

David Winterburn commented on Sep 21, 2020

Please try this: `

->pipe(new ColumnMeta(array(
    "Column_1" => array(
        "label" => "Column 1",
        "type" => "number",
        "decimals" => 2, //showing 2 numbers after floating point,
        "thousandSeparator" => ",",
        "decimalPoint" => "."
    ),
)))
->pipe($this->dataStore("myDs"));

Daniel Cordeiro commented on Sep 21, 2020

It Works.

But date cells always return wrong. I open a another topic for this (#1626).

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
None yet

Excel