KoolReport's Forum

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

What is the best way to export a datastore to excel (for some debugging reason)? #2208

Open Eugene opened this topic on on Jul 15 - 7 comments

Eugene commented on Jul 15


In the middle of my report.view file after some processes, I have a variable $tmp_datastore with a datastore. How is better to export it to excel?

I tried to use the Excel Table widget and do like this

        "dataSource" => $tmp_datastore

But it looks like I need some parameters or something like that because I get the error

PHP Notice:  Undefined property: stock_v4::$excelExportHandler in .../koolreport/excel/Widget.php on line 16, 
PHP Fatal error:  Uncaught Error: Call to a member function setWidgetParams() on null in .../koolreport/excel/Widget.php:16, 

I need only to save the datastore as excel - the format, etc is not important. How to do it with minimum code in a view file - it is a bit complicated to wrap my report to something else or create some special excel report files - I thought the widget is exactly for this purpose.

Sebastian Morales commented on Jul 16

Would you mind posting your export to excel command and your excel view file? Tks,

Eugene commented on Jul 16

Hi, I am a bit confused. I meant I wish to use Excel Widget Based on docs here https://www.koolreport.com/docs/excel/excel_widgets/ it is not so clear how to use it I don't have any special excel view file. Just usual report structure. index, report, report.view Could you show how to export to excel the datastore from $tmp_datastore to which I have access in report.view.php

Eugene commented 7 days ago

Dear KoolReport

could you give me an example here also?

Is it possible to do export from the current report without adding any extra excel.view files etc. I thought the Excel Widget can be used but i cannot understand how to do it the easiest way.

Sebastian Morales commented 5 days ago

If you only want to export certain datastores. please check this documentation:


$report = new MyReport;
    "dataStores" => array(
        'salesReport' => array(
                0, 1, 2, 'column3', 'column4' //if not specifying, all columns are exported
Eugene commented 5 days ago

Thanks. But it is not exactly what I need.

What I have now - report.php file where finally I get the datastore but after that, I add some calculated columns in report.view.php file and save the result in $tmp_datastore. And I wish to export to excel the $tmp_datastore.

So how to do this?

Eugene commented 14 hours ago


Sebastian Morales commented 38 mins ago

Ok, to make the code in your report view run you could use this command in your export.php file:

// in your view code, save $tmp_datastore to a datastore of the report, for example
$ds = $this->dataStore("tmp");
// now that $this->dataStore("tmp") is available you could export it

$report = new MyReport();
$report->render(true); // run the view code, adding true argument makes this return a html string without echoing it to output

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
help needed