Last active
August 1, 2022 13:51
-
-
Save woduda/00cc32417b4be0916db07f88e421ba2c to your computer and use it in GitHub Desktop.
Example for koolreport/pro 5.16.2 produces corrupted Excel data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../vendor/autoload.php'; | |
use koolreport\KoolReport; | |
use koolreport\datasources\ArrayDataSource; | |
use koolreport\excel\ExcelExportable; | |
use koolreport\processes\ColumnMeta; | |
class TestReport extends KoolReport | |
{ | |
use ExcelExportable; | |
public function settings() | |
{ | |
return [ | |
"dataSources" => [ | |
"data" => [ | |
"class" => ArrayDataSource::class, | |
"dataFormat" => "associate", | |
], | |
], | |
]; | |
} | |
public function setup() | |
{ | |
$this->src('data') | |
->load([ | |
['id' => '182398', "customerName"=>"Johny Deep", "dollar_sales"=>0], | |
['id' => '182399', "customerName"=>"Angelina Jolie", "dollar_sales"=>0], | |
['id' => '182400', "customerName"=>"Brad Pitt", "dollar_sales"=>0], | |
['id' => '700001', "customerName"=>"Nocole Kidman", "dollar_sales"=>0], | |
]) | |
->pipe(new ColumnMeta([ | |
'id' => [ | |
'label' => 'ID', | |
'type' => 'number', | |
], | |
'customerName' => [ | |
'label' => 'Customer Name', | |
'type' => 'string', | |
], | |
'dollar_sales' => [ | |
'label' => 'Dollar Sales', | |
'type' => 'number', | |
], | |
])) | |
->pipe($this->dataStore("x")); | |
} | |
} | |
$report = new TestReport(); | |
$report->run()->exportToExcel([ | |
"dataStores" => [ | |
'x' => [ | |
"columns" => [ | |
'id', | |
'customerName', | |
'dollar_sales', | |
], | |
], | |
], | |
])->toBrowser("report.xlsx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment