KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Pivot Table Export to Excel Format #764

Open Oya Kaynar opened this topic on on Mar 27, 2019 - 4 comments

Oya Kaynar commented on Mar 27, 2019

Hi, I created a pivot table in view with extra parameters to show column headers. I modified koolreport\pivot\widgets\PivotTable.php add columns as a parameter and modified the PivotTable.tpl.php file iterate on columns and echo as header.

view file;

PivotTable::create(array(
    "dataStore" => $this->dataStore($this->reportName),
    "columns" => array( 
        "PRODUCTDEFCODE" => array("label" => "Ürün Adı"),
        "KRITIKSTOCK" => array("label" => "Kritik Stok"),
        "MINSTOCK" => array("label" => "Min Stok"),
        "MAXSTOCK" => array("label" => "Max Stok"),
        "MIAD" => array("label" => "Miad"),
    ),
    "columnDimension" => "column",
    "rowDimension" => "row",
    'totalName' => 'Toplam',
    'hideSubtotalRow' => true,
    'width' => '100%',
    "cssClass" => array(
        "table" => "table-bordered table-striped table-hover",
    ), "options" => array(
        "searching" => true,
        "paging" => true,
        "fixedHeader" => true,
    ),
));

Datastore setup code;

$this->getDataSource()->query($this->query)->pipe(new ColumnMeta(array(
    "MINSTOCK"=>array(
        'type' => 'number',
    ),
    "MAXSTOCK"=>array(
        'type' => 'number',
    ),
    "TOTAL"=>array(
        'type' => 'number',
    ),
)))->pipe(new FillNull(array(
    "newValue"=>"",
    "targetColumnType"=>"number",
)))->pipe(new CalculatedColumn(array(
    "PRODUCTDEFCODE"=>array(
        "exp" => function($data){
            return $data['PRODUCTDEFNAME'] . " (".$data['PRODUCTDEFCODE'].") ";
        },
        "type"=>"string",
    )
)))->pipe(new Pivot(array(
    "dimensions"=>array(
        "column"=>"",
        "row"=>"PRODUCTDEFCODE, KRITIKSTOCK, MINSTOCK, MAXSTOCK, MIAD",
    ),
    "aggregates"=>array(
        "sum"=>"TOTAL",
    )
)))->pipe($this->dataStore($this->reportName));

And Result of View;

Then export this pivot table to excel like in samples,

PivotTable::create(array(
    "dataSource" => $this->dataStore($this->reportName),
));

Excel Result;

Is it possibe to modify pivot excel like in view? I tried so much but I couldn't modify excel.

David Winterburn commented on Mar 28, 2019

Hi Oya Kaynar,

At the moment exporting a Pivot datastore to excel has not has the option to hide subtotal rows/columns. We will consider your question as a feature to add to future version of the Pivot package.

Please post in this topic in 2 or 3 weeks time for a possible update of the issue. Thanks!

Oya Kaynar commented on Mar 28, 2019

Thank you,

I will repost this in 3 weeks,

Have a good work

Oya Kaynar commented on Apr 30, 2019

Hi David,

Did you find a solution about this issue?

David Winterburn commented on May 1, 2019

Hi Oya Kaynar,

We are still working on this feature. Hiding the subtotal row/column with html is easier as we could use CSS to hide elements. For excel format, we have to find a new solution. We will let you know as soon as a working version is available. Thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Excel