KoolReport's Forum

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

Export excel with two sheets #1084

Closed Atul opened this topic on on Sep 13, 2019 - 8 comments

Atul commented on Sep 13, 2019

Hi, I am exporting excel using koolreport via array. That is running fine. Now I want to add one more sheet to in the same exported excel.

require_once "../koolreport/autoload.php";

class ExcelReport extends \koolreport\KoolReport
{

    use \koolreport\export\Exportable;
    use \koolreport\excel\ExcelExportable;
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["data"],
                    "dataFormat"=>"associate",
                )
            )
        );
    }   
    public function setup()
    {
        $this->src('data')
        ->pipe($this->dataStore('Billing'));
    }
}


$report = new ExcelReport(array(
			"data"=>$rpt_get_bill_list
		));
$report->run();
$report->exportToExcel(array(
		"dataStores" => array(
		    'Billing' => array(
			"columns"=>array(
				            )
				        )
				    )
				))->toBrowser("rpt_get_bill_list.xlsx");

Can anyone help me, how can I add another sheet ?

KoolReport commented on Sep 13, 2019

Hi Atul,

please try to add another dataStore and do the same as Billing. Each dataStore will be exported to a sheet of excel.

Atul commented on Sep 13, 2019

Hi, but, can you please let me know how to pass data to this new added datasource, because for billing, we are passing data via "data"=>$rpt_get_bill_list.

KoolReport commented on Sep 13, 2019

So you have a list of billing, and you want to separate them into 2 sheets or you have more data like list of other thing that you want another sheet to store it?

Atul commented on Sep 13, 2019

Hi, Thanks for quick reply.

I have list of another data, that i want show in separate sheet of the same xls.

KoolReport commented on Sep 13, 2019

So, you do:

$report = new ExcelReport(array(
    "bill_list"=>$rpt_get_bill_list,
    "another_list"=>$rpt_get_another_list,
));

In the setting(), you define another source for "another_list" params:

        return array(
            "dataSources"=>array(
                "bill_list"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["bill_list"],
                    "dataFormat"=>"associate",
                ),
                "another_list"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["another_list"],
                    "dataFormat"=>"associate",
                )
            )
        );

Now you have two sources, you can pipe each source to 2 different dataStores:

        $this->src('bill_list')
        ->pipe($this->dataStore('Billing'));
        $this->src('another_list')
        ->pipe($this->dataStore('Another'));

And then do export:

$report->exportToExcel(array(
		"dataStores" => array(
		    'Billing' => array(
			"columns"=>array()
                     ),
		    'Another' => array(
			"columns"=>array()
                     ),
                )
))->toBrowser("rpt_get_bill_list.xlsx");
Atul commented on Sep 13, 2019

Thank you, Let me try this....

Atul commented on Sep 17, 2019

Thank you, its works for me...

KoolReport commented on Sep 17, 2019

Awesome!

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

None