I had already tried this procedure, but when I add input <input type = 'hidden' name = 'koolPivotUpdate' value = 1 />, the export fails. Without this parameter the export works, but exports only the starting matrix and with a single row and a single column. Already with two he goes wrong.
I'll give you the code
<?php
use \koolreport\pivot\widgets\PivotMatrix;
<form method="post">
<button class="btn btn-primary" formaction='/report/availability?csv=1'>Export Excel</button>
<input type='hidden' name='koolPivotUpdate' value=1 />
<div class="clearb"></div>
PivotMatrix::create(array(
"id" => "pivotMatrix2",
'dataSource' => $this->dataStore('pivotData2'),
'waitingFields' => array(
'WEEKDAY_NAME' => 'label',
'WEEK_OF_MONTH_NUM' => 'label',
'NUM_ZONA' => 'label',
'TICKET_DESCRIPTION' => 'label',
),
'headerMap' => array(
'WEEKDAY_NAME' => 'Giorno settimana',
'MONTH_LONG_NAME' => 'Mese',
'EURO_TXN_VALUE - SUM' => 'Somma Vendite',
'EURO_TXN_VALUE - COUNT' => 'Totale Vendite',
'WEEK_OF_MONTH_NUM' => 'Settimana',
'NUM_ZONA' => 'Zone',
'TICKET_DESCRIPTION' => 'Tipo di prodotto',
),
'paging' => array(
'size' => 100,
'maxDisplayedPages' => 5,
'sizeSelect' => array(5, 10, 20, 50, 100)
)
));
?>
</form>
<?php
Page action form
if( !empty( $_GET['csv'] ) ) {
$report->run();
$report->exportToExcel('MyKReportAvailabilityExcel')->toBrowser("reportAvailability.xlsx");
exit;
}
?>
File MyKReportAvailabilityExcel.view.php
<?php
use \koolreport\excel\Table;
use \koolreport\excel\PivotTable;
use \koolreport\excel\BarChart;
use \koolreport\excel\LineChart;
$allStylesArray = [
'font' => [
'name' => 'Calibri', //'Verdana', 'Arial'
'size' => 30,
'bold' => false,
'italic' => FALSE,
'underline' => 'none', //'double', 'doubleAcCOUNTing', 'single', 'singleAcCOUNTing'
'strikethrough' => FALSE,
'superscript' => false,
'subscript' => false,
'color' => [
'rgb' => '000000',
'argb' => 'FF000000',
]
],
'alignment' => [
'horizontal' => 'general',//left, right, center, centerContinuous, justify, fill, distributed
'vertical' => 'bottom',//top, center, justify, distributed
'textRotation' => 0,
'wrapText' => false,
'shrinkToFit' => false,
'indent' => 0,
'readOrder' => 0,
],
'borders' => [
'top' => [
'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
'color' => [
'rgb' => '808080',
'argb' => 'FF808080',
]
],
//left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
],
'fill' => [
'fillType' => 'none', //'solid', 'linear', 'path', 'darkDown', 'darkGray', 'darkGrid', 'darkHorizontal', 'darkTrellis', 'darkUp', 'darkVertical', 'gray0625', 'gray125', 'lightDown', 'lightGray', 'lightGrid', 'lightHorizontal', 'lightTrellis', 'lightUp', 'lightVertical', 'mediumGray'
'rotation' => 90,
'color' => [
'rgb' => 'A0A0A0',
'argb' => 'FFA0A0A0',
],
'startColor' => [
'rgb' => 'A0A0A0',
'argb' => 'FFA0A0A0',
],
'endColor' => [
'argb' => 'FFFFFF',
'argb' => 'FFFFFFFF',
],
],
];
$styleArray = [
'font' => [
'italic' => true,
'color' => [
'rgb' => '808080',
]
],
];
?>
<div>Totale vendite per periodo</div>
<div>
PivotTable::create(array(
"dataSource" => $this->dataStore('pivotData2'),
'hideSubTotalRows' => true,
'hideSubTotalColumns' => true,
'hideGrandTotalRow' => true,
'hideGrandTotalColumn' => true,
"showDataHeaders" => true,
'map' => array(
'rowField' => function($rowField, $fieldInfo) {
return $rowField;
},
'columnField' => function($colField, $fieldInfo) {
return $colField;
},
'dataField' => function($dataField, $fieldInfo) {
//Util::prettyPrint($fieldInfo);
$v = $dataField;
if ($v === 'EURO_TXN_VALUE - SUM')
$v = 'Somma vendite';
else if ($v === 'EURO_TXN_VALUE - COUNT')
$v = 'Totale vendite';
return $v;
},
'dataHeader' => function($dataField, $fieldInfo) {
//Util::prettyPrint($fieldInfo);
$v = $dataField;
if ($v === 'EURO_TXN_VALUE - SUM')
$v = 'Somma vendite';
else if ($v === 'EURO_TXN_VALUE - COUNT')
$v = 'Totale vendite';
return $v;
},
'waitingField' => function($waitingField, $fieldInfo) {
return $waitingField;
},
'rowHeader' => function($rowHeader, $headerInfo) {
//Util::prettyPrint($headerInfo);
$v = $rowHeader;
if (isset($headerInfo['childOrder']))
$v = $headerInfo['childOrder'] . ". " . $v;
return $v;
},
'columnHeader' => function($colHeader, $headerInfo) {
$v = $colHeader;
if ($headerInfo['fieldName'] === 'orderYear')
$v = 'Year-' . $v;
else if ($headerInfo['fieldName'] === 'orderQuarter')
$v = 'Quarter-' . $v;
if (isset($headerInfo['childOrder']))
$v = $headerInfo['childOrder'] . ". " . $v;
return $v;
},
'dataCell' => function($value, $cellInfo) {
return $value;
//Util::prettyPrint($cellInfo);
$rfOrder = $cellInfo['row']['fieldOrder'];
$cfOrder = $cellInfo['column']['fieldOrder'];
$df = $cellInfo['fieldName'];
$dfOrder = $cellInfo['fieldOrder'];
// return "$rfOrder:$cfOrder:$df. $value";
return $cellInfo['formattedValue'];
},
),
'excelStyle' => array(
'dataField' => function($dataFields) use ($styleArray) {
return $styleArray;
},
'dataHeader' => function($dataFields, $fieldInfo) use ($styleArray) {
return $styleArray;
},
'columnHeader' => function($header, $headerInfo) use ($styleArray) {
return $styleArray;
},
'rowHeader' => function($header, $headerInfo) use ($styleArray) {
return $styleArray;
},
'dataCell' => function($value, $cellInfo) use ($styleArray) {
return $styleArray;
},
)
));
?>
</div>
</div>
Cosa c'è di sbagliato?