KoolReport's Forum

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

Custom column name in pivot table excel export #2155

Open Rohit Savaliya opened this topic on on Jun 24, 2021 - 7 comments

Rohit Savaliya commented on Jun 24, 2021

I use Pivot 2D and we need custom name of column in excel as well in HTML, because of it is not a value return by database, the values is already in view part of file as headerMap switch case but if we place this value in column then it show it will show {{other}} in html and exported excel.

->pipe(new Pivot2D(array(
            "dimensions"=>array(
                "column" => "dateyear, quantity - sum",  OR "column" => "dateyear, Total Quantity", 
                "row" => "users_zone_c",
            ),

in view part

'headerMap' => function($v, $f) {
        switch ($v) {
            case 'quantity - sum': return 'Total Quantity';

Please help us to fix this

Sebastian Morales commented on Jun 28, 2021

Pls check our map property of the Excel package's PivotTable widget (not the Pivot package's one):

https://www.koolreport.com/docs/excel/excel_widgets/#pivottable-widget-(version-%3E=-6.0.0)

Rohit Savaliya commented on Jul 1, 2021

I think you can not understand my issue, lets see it with an example when I render Pivot2D into the browser it look like bellow but when i export it into the excel sheet its look like this

you can see that in excel file there is no any column header show, like in GUI in browser e.g. Service Charge, Parts Charges etc.

my aim is place that all header text (Total Quantity,Service Charge,Parts Charges etc) into the excel file

Please tell me solution to do the same.

Sebastian Morales commented on Jul 2, 2021

Pls try this in your excel view and let us know if it works for you or not:

    \koolreport\excel\PivotTable::create(array(
        ...
        'map' => array(
            ...
            'dataField' => function($dataField, $fieldInfo) {
                $v = $dataField;
                switch ($v) {
                    case 'quantity - sum': return 'Total Quantity';
                    ...
                return $v;
            }, 
Rohit Savaliya commented on Jul 2, 2021

No it is not work, it just change the left side list i show you bellow.

but there is no effect in excel sheet please tell me method to perform this.

Sebastian Morales commented on Jul 5, 2021

Ok, I see your point. Please add "showDataHeaders" property and its map to your excel's PivotTable like this:

    \koolreport\excel\PivotTable::create(array(
        ...    
        "showDataHeaders" => true,
        'map' => array(
            ...
            'dataField' => function($dataField, $fieldInfo) {
                $v = $dataField;
                switch ($v) {
                    case 'quantity - sum': return 'Total Quantity';
                    ...
                return $v;
            },         
            'dataHeader' => function($dataHeader, $fieldInfo) {
                $v = $dataHeader;
                switch ($v) {
                    case 'quantity - sum': return 'Total Quantity';
                    ...
                return $v;
            },   
Rohit Savaliya commented on Jul 6, 2021

No, still you are not understand the problem, my problem is there is no heading in excel sheet, An excel sheet not in GUI, please understand this, after apply your above solution there is no any column header show in excel sheet, this issue i show you in pic, i already have column heading in browser but not in exported excel sheet and i want it. effect after apply you suggestion its help in column name for GUI like this

but when i export it in excel file, it is exported without column headings, like this

but i want all heading name in it, you can see that excel file has no any heading for column G,H,I,J,K,L,M,N,O and we need this because without that we can not recognise that what is represent by the column it self.

Hope this explain help you to understand the issue, it so clear that we want column name in the excel sheet. Please suggest something to do the same.

Sebastian Morales commented on Jul 7, 2021

That's what "showDataHeaders" => true is for, both in excel exporting and web rendering. Pls post your excel template code and your Excel package version which could be found in file koolreport/excel/composer.json. Rgds,

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
None yet

None