KoolReport's Forum

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

Export a manual array to excel #1010

Open SOFMAN opened this topic on on Jul 24, 2019 - 2 comments

SOFMAN commented on Jul 24, 2019

Good morning

I would like you to help me export the data array to excel because when exporting I get the following message: "Call to a member function meta() on array" . From a mysql query I get the data and build an array, the code is the following:

arrayFinished=[];
$date="2019-07-24";
foreach ($dataQuery as $data) {
    $idcustomer = $data->idcustomer;
    $name= $data->name;
    $arrayDet = array("IDCUSTOMER" => $idcustomer, "CUSTOMER" => $name);
	$valor=0;
	foreach ($dataQuery2 as $data2) {
        if ($data2->idcustomer == $idcustomer) {
            $valor = $data2->value;
        }
    }
	$arrDet[$date] = floatval($valor);
	array_push(arrayFinished, $arrayDet);
}
$arrayColumnsExcel=["IDCUSTOMER","CUSTOMER","2019-07-24"]
$this->dataStore('arrayFinished')->data($arrayFinished);
$this->dataStore('arrayColumnsExcel')->data($arrayColumnsExcel);

To export to Excel I do the following:

\koolreport\excel\Table::create(array(
"dataSource" => $this->dataStore("arrayFinished"),
"columns"=>$this->dataStore("arrayColumnsExcel")->data()
 ));

Regards

SOFMAN commented on Jul 25, 2019

KoolReport support if you are able to help me please answer the forum.

KoolReport commented on Jul 27, 2019

The "columns" will receive array, not datastore. Also you can do this to create new datastore with data:

$myDataStore = new \koolreport\core\DataStore($data);

and then you can assign $myDataStore to the "dataSource" of widget.

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

Excel