This example demonstrates how to export table with row detail information to an excel file.
\koolreport\excel\Table::create(array(
...
"rowDetailTable" => function($row) {
return
[
[
[
"cellValue" => $row["productName"] . " : " . $row["dollar_sales"],
"rowspan" => 3,
"colspan" => 2,
],
],
];
}
));
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
require_once "../../../load.koolreport.php";
use \koolreport\processes\Map;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;
class MyReport extends koolreport\KoolReport
{
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;
use \koolreport\excel\BigSpreadsheetExportable;
function settings()
{
return array(
"dataSources" => array(
"dollarsales"=>array(
'filePath' => '../../../databases/customer_product_dollarsales2.csv',
'fieldSeparator' => ';',
'class' => "\koolreport\datasources\CSVDataSource"
),
)
);
} function setup()
{
$this->src('dollarsales')
->pipe(new Limit(array(10, 0)))
->pipe($this->dataStore('sales'));
}
}
<?php
use \koolreport\datagrid\DataTables;
?>
<div class="report-content">
<div style='text-align: center;margin-bottom:30px;'>
<h1>Excel Row Detail Table</h1>
<p class="lead">Exporting excel table with row detail table</p>
<form method="post">
<button type="submit" class="btn btn-primary" formaction="export.php?type=excel">Download Excel</button>
<button type="submit" class="btn btn-primary" formaction="export.php?type=bigspreadsheet">Download Big Spreadsheet</button>
</form>
</div>
<div class='box-container'>
<div>
<?php
DataTables::create(array(
"name" => "rowDetailTable",
"dataSource" => $this->dataStore('sales'),
"columns"=>array(
"customerName",
"productLine",
// "productName",
// "dollar_sales"=>array(
// "type"=>"number",
// )
),
"rowDetailData" => function($row) {
return $row["productName"] . " : " . $row["dollar_sales"];
},
"onReady" => "function() {
rowDetailTable.on( 'draw', function () {
KRrowDetailTable.expandAllRowDetails();
} );
KRrowDetailTable.expandAllRowDetails();
}",
"width" => "100%"
));
?>
</div>
</div>
</div>
<?php
$sheet1 = "Sales by Customer";
?>
<div sheet-name="<?php echo $sheet1; ?>">
<div>Orders Table</div>
<div>
<?php
\koolreport\excel\Table::create(array(
"dataSource" => $this->dataStore('sales'),
"columns" => [
"customerName", "productLine",
// "productName", "dollar_sales"
],
"rowDetailTable" => function($row) {
return [
[
"",
"",
[
"cellValue" => $row["productName"] . " : " . $row["dollar_sales"],
"rowspan" => 3,
"colspan" => 2,
],
],
];
}
));
?>
</div>
</div>
<?php
include "MyReport.php";
$report = new MyReport;
$report->run();
$exportType = $_GET["type"];
if ($exportType === "excel") {
$report->exportToExcel('MyReportExcel')->toBrowser("MyReportExcel.xlsx");
} else {
$report->exportToXLSX('MyReportExcel')->toBrowser("MyReportBigSpreadsheet.xlsx");
}
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 |
2003 |
1 |
3726.45 |
Vitachrome Inc. |
1936 Mercedes-Benz 500K Special Roadster |
Vintage Cars |
2003-01-10 00:00:00 |
10 |
1 |
2003 |
1 |
1768.33 |
Baane Mini Imports |
1952 Alpine Renault 1300 |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
5571.8 |
Baane Mini Imports |
1962 LanciaA Delta 16V |
Classic Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
5026.14 |
Baane Mini Imports |
1958 Setra Bus |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
3284.28 |
Baane Mini Imports |
1940 Ford Pickup Truck |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
3307.5 |
Baane Mini Imports |
1926 Ford Fire Engine |
Trucks and Buses |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
1283.48 |
Baane Mini Imports |
1913 Ford Model T Speedster |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2489.13 |
Baane Mini Imports |
1934 Ford V8 Coupe |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2164.4 |
Baane Mini Imports |
18th Century Vintage Horse Carriage |
Vintage Cars |
2003-01-29 00:00:00 |
29 |
1 |
2003 |
1 |
2173 |