Hi KoolReport team,
I'm Sowmya. I'm Koolreport Pro User. I implemented Koolreport4 in CodeIgniter3. I got the Grid Output. But My Excel file is not Downloading. When I click on "Download" button, it redirects me to the empty page....
My Code:
Home.php:
public function index()
{
include APPPATH."reports\ExcelReport.php";
$report = new ExcelReport;
$report->run()->render();
}
export.php:
<?php
include "ExcelReport.php";
$report = new ExcelReport;
$report->run();
$report->exportToExcel('ExcelReport')->toBrowser("ExcelReport.xlsx");
ExcelReport.php:
<?php
require APPPATH."/libraries/koolreport/core/autoload.php";
use \koolreport\excel\ExcelDataSource;
use \koolreport\processes\Limit;
use \koolreport\processes\Filter;
use \koolreport\cube\processes\Cube;
use \koolreport\pivot\processes\Pivot;
class ExcelReport extends \koolreport\KoolReport
{
use \koolreport\export\Exportable;
use \koolreport\excel\ExcelExportable;
public function settings()
{
return array(
"assets"=>array(
"path"=>"../../assets",
"url"=>"assets",
),
"dataSources"=>array(
"invoice"=>array(
"connectionString"=>"sqlsrv:Server=*****;Database=*****",
"username"=>"sa",
"password"=>"*****",
"charset"=>"utf8"
)
)
);
}
public function setup()
{
$this->src('invoice')
->query("select CostCentre,MONTH(Month) as MonFiled,YEAR(Month) as YearField,
SUM(InvValue) as InvoiceValue
from MonthWiseSalesSummeries
group by CostCentre,MONTH(Month),YEAR(Month)
order by CostCentre,MONTH(Month),YEAR(Month)")
->pipe($this->dataStore("excelDataStore"));
}
}
ExcelReport.view.php
<body>
<?php
Table::create(array(
"dataSource" => $this->dataStore('excelDataStore'),
"columns"=>array(
"CostCentre",
"InvoiceValue"=>array(
"type"=>"number",
"label"=>"InvoiceValue",
"prefix"=>"$"
)
),
"paging"=>array(
"pageSize"=>5
)
));
?>
```
### ExcelReport.excel.php
<div sheet-name="<?php echo $sheet1; ?>">
<?php
$styleArray = [
----------
---------
],
'alignment' => [
--------,
--------
],
'borders' => [
--------
---------
],
'fill' => [
----------
-------------
],
'startColor' => [
---------
---------
],
'endColor' => [
----------
------------
];
?>
<div cell="A1" range="A1:H1" excelstyle='<?php echo json_encode($styleArray); ?>' >
Sales Report
</div>
<div>
<?php
Table::create(array(
"dataSource" => $this->dataStore('excelDataStore'),
// "dataSource" => 'orders',
"headersExcelStyle" => [
'CostCentre' => [
'font' => [
'italic' => true,
'color' => [
'rgb' => '808080',
]
],
],
'InvoiceValue'=> [
'font' => [
'italic' => true,
'color' => [
'rgb' => '808080',
]
],
]
],
"columnsExcelStyle" => [
'CostCentre' => [
'font' => [
'italic' => true,
'color' => [
'rgb' => '808080',
]
],
],
'InvoiceValue' => [
'font' => [
'italic' => true,
'color' => [
'rgb' => '808080',
]
],
]
],
));
?>
</div>
<?php
$datastores = ['excelDataStore'];
foreach ($datastores as $datastore)
{
if ($datastore === 'excelDataStore')
{
$title = 'excelDataStore';
$name = 'customerSales';
$column = 'CostCentre';
}
}
?>
<div>
<?php echo $title; ?>
</div>
<div>
<?php
Table::create(array(
"name" => $name,
// "dataSource" => $this->dataStore($datastore),
"dataSource" => $datastore,
"columns" =>[
$column, "InvoiceValue"
],
));
?>
</div>
<?php }
?>
<div>
<?php
PivotTable::create(array(
"dataSource" => 'excelDataStore',
));
?>
</div>