I am trying to export array to Excel dynamically. How to define dynamic column names in settings "data"=>array(
array("bill_number"=>"Johny Deep","bill_date"=>100,"ptm_mr_number"=>"Johny Deep","vst_number"=>100),
// "columns"=>array("bill_number", "bill_date","ptm_mr_number","PatientName","vst_number")
),
- If "data"=>array(), export file is null,
- If "data"=>array("columns"=>array("bill_number", "bill_date","ptm_mr_number","PatientName","vst_number")), export file is null,
How to define this dynamically as we are not aware of column names. how to set them dynamically? Below is the code I am using--
In Export Excel File /------------------------------------------/ <?php
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"=>array(
array("bill_number"=>"Johny Deep","bill_date"=>100,"ptm_mr_number"=>"Johny Deep","vst_number"=>100),
// "columns"=>array("bill_number", "bill_date","ptm_mr_number","PatientName","vst_number")
),
"dataFormat"=>"associate",
)
)
);
}
public function setup()
{
$this->src('data')
->pipe($this->dataStore('Billing'));
}
}
In Controller FIle /-------------------------------------------------------/ include("ExcelReport.php");
$this->loadKoolReport();
$report = new ExcelReport;
// $report = new ExcelReport;
$report->run();
$report->dataStore('Billing')->data($rpt_get_bill_list);
$report->exportToExcel(array(
"dataStores" => array(
'Billing' => array(
"columns"=>array(
)
)
)
))->toBrowser("myreport.xlsx");