Skip to content

Instantly share code, notes, and snippets.

@woduda
Last active August 1, 2022 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woduda/00cc32417b4be0916db07f88e421ba2c to your computer and use it in GitHub Desktop.
Save woduda/00cc32417b4be0916db07f88e421ba2c to your computer and use it in GitHub Desktop.
Example for koolreport/pro 5.16.2 produces corrupted Excel data
<?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