In many case, data is stored in big CSV or spreadsheet files. The BigSpreadsheetDataSource in Excel package will help us to read data from those file and pipe their data into our processing chain.
public function settings()
{
return array(
"dataSources"=>array(
"big_excel"=>array(
"class"=>'\koolreport\excel\BigSpreadsheetDataSource',
"filePath"=>"/var/storage/big_sales.xlsx",
),
)
);
}
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";
use \koolreport\excel\ExcelDataSource;
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\ColumnMeta;
class MyReport extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"excel"=>array(
'class' => '\koolreport\excel\BigSpreadsheetDataSource',
"filePath"=>dirname(__FILE__)."/../../../databases/customer_product_dollarsales2.xlsx",
)
)
);
}
protected function setup()
{
$this->src("excel")
->pipe(new Group(array(
"by"=>"orderMonth",
"sum"=>"dollar_sales",
)))
->pipe(new Sort(array(
"orderMonth"=>"asc",
)))
->pipe(new ColumnMeta(array(
"orderMonth"=>array(
"type"=>"date",
"format"=>"n",
"displayFormat"=>"M"
),
"dollar_sales"=>array(
"prefix"=>'$',
"type" => "number",
)
)))
->pipe($this->dataStore("data"));
}
}
<?php
use \koolreport\widgets\google\LineChart;
use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
<div class="text-center">
<h1>Big Excel Report</h1>
<p class="lead">The exampe show how to use a big Excel file as datasource</p>
</div>
<?php
LineChart::create(array(
"dataSource"=>$this->dataStore("data"),
"columns"=>array("orderMonth","dollar_sales")
));
?>
<?php
Table::create(array(
"dataSource"=>$this->dataStore("data"),
"columns"=>array("orderMonth","dollar_sales")
));
?>
</div>
customerName | productName | productLine | orderDate | orderDay | orderMonth | orderYear | orderQuarter | dollar_sales |
Vitachrome Inc. |
1937 Lincoln Berline |
Vintage Cars |
2003-01-10 00:00:00 |
10 |
1 |
2,003 |
1 |
3,726 |
Vitachrome Inc. |
1936 Mercedes-Benz 500K Special Roadster |
Vintage Cars |
2003-01-10 00:00:00 |
10 |
1 |
2,003 |
1 |
1,768 |
Baane Mini Imports |
1952 Alpine Renault 1300 |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
5,572 |
Baane Mini Imports |
1962 LanciaA Delta 16V |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
5,026 |
Baane Mini Imports |
1958 Setra Bus |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
3,284 |
Baane Mini Imports |
1940 Ford Pickup Truck |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
3,308 |
Baane Mini Imports |
1926 Ford Fire Engine |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
1,283 |
Baane Mini Imports |
1913 Ford Model T Speedster |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
2,489 |
Baane Mini Imports |
1934 Ford V8 Coupe |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
2,164 |
Baane Mini Imports |
18th Century Vintage Horse Carriage |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2,003 |
1 |
2,173 |