KoolReport's Forum

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

Export Excel Custom Column Names #330

Open V Vijaykumarr opened this topic on on Jun 21, 2018 - 4 comments

V Vijaykumarr commented on Jun 21, 2018

Hello,

I would like to change the default column names to custom column name when i export the View to excel.

require_once "AchievedProduction.php";
$report = new AchievedProduction;
$report->run()->exportToExcel()->toBrowser("Achieved Production.xls");

Thanks.

David Winterburn commented on Jun 22, 2018

Hi there,

To use custom column name when exporting, in your report's setup function please change the column meta's label property to that custom name before saving to the datastore. For example:

->pipe(new \koolreport\processes\ColumnMeta(function($colName, $colMeta, $colPos){
    if ($colName === 'dollar_sales')
        return array(
            'label' => 'Sales',
        );
    else if ($colName === 'orderQuarter')
        return array(
            'label' => 'Quarter',
        ); 
    else
        return $colMeta;
}))
->->pipe($this->dataStore('myDatastore1'));

If this doesn't work for you, please send us an email to support@koolphp.net, we will send you the latest version of ExcelExport.php file. Thanks!

V Vijaykumarr commented on Jun 22, 2018

After i add the above lines, I get this error when i download the excel report.

<b>Notice</b>:  Undefined index: type in <b>C:\xampp\htdocs\reports\koolreport\packages\excel\ExcelExportable.php</b> on line <b>28</b><br />													
<br />													
<b>Notice</b>:  Undefined index: type in <b>C:\xampp\htdocs\reports\koolreport\packages\excel\ExcelExportable.php</b> on line <b>28</b><br />													
ÐÏࡱá;þÿ	þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

This is the Code is used.

$this->src('slpdb')
        ->query("SELECT quote.id as `Total No of Units`,quote.date as `Month`,quote.price as `Sales Value`,quote.production_total as `Production`,real_estate_property.builtup_area_sqft as `Total Sold Area (Sqft)` FROM `quote` LEFT JOIN `real_estate_property` ON quote.property_test_id=real_estate_property.id where quote.status='Approved' AND quote.deleted=0 GROUP BY quote.id")
        ->pipe(new TimeBucket(array(
            "Month"=>"month"
        )))
        ->pipe(new \koolreport\processes\ColumnMeta(function($colName, $colMeta, $colPos){
          if ($colName === 'Sales Value')
              return array(
                  'label' => 'Sales',
              );
          else if ($colName === 'Production')
              return array(
                  'label' => 'Production value',
              );
          else
              return $colMeta;
          }))
        ->pipe(new Group(array(
            "by"=>"Month",
            "sum"=>"Sales Value, Production, Total Sold Area (Sqft)",
            "count"=>"Total No of Units",
        )))
        ->pipe($this->dataStore('Achieved Production'));
David Winterburn commented on Jun 23, 2018

Hi,

We've sent you the latest version of the Excel package to your email. Please replace the older folder koolreport/packages/excel with the new version and let us know it it works for you. Thanks!

V Vijaykumarr commented on Jun 25, 2018

Same error mentioned above. Please help to resolve the above error when we download the excel file.

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