KoolReport's Forum

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

Export to Excel Returned Empty Table, But Has Columns #2244

Open Aqila Nasir opened this topic on on Aug 3, 2021 - 2 comments

Aqila Nasir commented on Aug 3, 2021

Below is the code, the datasource is from array which I pass as parameter;

// MyReport.php
    public function settings()
    {
        return array(
            "dataSources" => array(
                "data" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "data" => $this->params["report"],
                    "dataFormat" => "associate",
                )
            )
        );
    }

    function setup()
    {
        $this->src('data')
            ->pipe($this->dataStore("result"));
    }
}

The excel view is as follows:

// MyReportExcel.view.php
<?php
use koolreport\excel\Table;
use koolreport\excel\PieChart;

$sheet1 = "Something Title Title";
$title = "statistics";
?>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="Excel,HTML,CSS,XML,JavaScript">
<meta name="creator" content="John Doe">
<meta name="subject" content="subject1">
<meta name="title" content="title1">
<meta name="category" content="category1">

<div sheet-name="<?php echo $title; ?>">

    <div><?php echo $sheet1; ?></div>

    <div>
        <?php
        Table::create(array(
            "dataSource" => 'result',
        ));
        ?>
    </div>

</div>

I managed to export to excel, however the table is empty but the columns are printed out. I have tried to print the datastore using json_encode($this->dataStore('result')->data()); and it managed to print out the data just fine.

Aqila Nasir commented on Aug 3, 2021

I'm using koolreport-core version 5.1.0, however the excel package I received from Pro is 5.0.4.

This is the screenshot of the resulting file This is the screenshot of the resulting file

Aqila Nasir commented on Aug 3, 2021

Silly me. It seems that the array that I passed should be decoded using json_decode($array, true); instead of json_decode($array);

The excel file is now good. Topic is closed.

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

Excel