KoolReport's Forum

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

Not able to export to excel #985

Open Speedum Technologies opened this topic on on Jul 16, 2019 - 7 comments

Speedum Technologies commented on Jul 16, 2019

This is the class I have defined

class ExcelReport extends \koolreport\KoolReport
    
{

    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
    
}

and here's how I can export to excel

$report = new ExcelReport;
$report->run();
$report->exportToExcel()->toBrowser("MyReport.xlsx");

My question is, I have data stored in PHP array, how how can I export that data in excel. Please refer to the screenshot below:--

Thank You...

David Winterburn commented on Jul 16, 2019

Hi there,

Please use the ArrayDataSource with your array data in your report's setting, then in setup method pipe the datasource to a datastore. Finally in export the datastore to excel:

    $report->exportToExcel(array(
        'dataStores' => array(
            'myDataStore1'
        ),
    ))
    ->toBrowser("myReport.xlsx");

Let us know if you need anything else. Thanks!

Speedum Technologies commented on Jul 16, 2019

This is my class now

class ExcelReport extends \koolreport\KoolReport
	
{
    public function settings()
    {
        return array(
        	"dataSources"=>array(
            	"mydata"=>array(
                "class"=>"\koolreport\datasources\ArrayDataSource",
                "data"=>$this->params["data"],
                "dataFormat"=>"associate"
            	)
       	 	)
    	);
    }

    public function setup()
    {
        $this->src('mydata')
        ->pipe($this->dataStore("mydata"))
    }
}

and for export

                                $myData  = array(
				    array("name"=>"Peter","age"=>30),
				    array("name"=>"Mary","age"=>25),
				);
				
				$this->loadKoolReport();
				$report = new ExcelReport;
				$report->exportToExcel(array(
			        'dataStores' => array(
			            'myData'
			        ),
			    ))
			    ->toBrowser("myReport.xlsx");

still now its not even generating blank excel

David Winterburn commented on Jul 16, 2019

Would you please print_r($this->params["data"]) to see if it contains any data? Thanks!

David Winterburn commented on Jul 16, 2019

Ah, I think you forgot to let $report->run() before exportToExcel(). Without the run() method call, no datastore would be builded. Thanks!

Speedum Technologies commented on Jul 16, 2019

I have added the above syntax. Its getting error, would it be possible for us to connect over skype to accelerate debugging, I need to deliver this today...

David Winterburn commented on Jul 16, 2019

Hi,

Please try this code:

                                $myData  = array(
				    array("name"=>"Peter","age"=>30),
				    array("name"=>"Mary","age"=>25),
				);
				
				$this->loadKoolReport();
				$report = new ExcelReport(array(
                                    "data" => $myData
                                ));
                                $report->run();
				$report->exportToExcel(array(
			        'dataStores' => array(
			            'mydata'
			        ),
			    ))
			    ->toBrowser("myReport.xlsx");

If it doesn't work, contact us via email to support@koolphp.net. Thanks!

Speedum Technologies commented on Jul 16, 2019

Its still producing error, I have mailed to the support team

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

None