KoolReport's Forum

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

BigSpreadsheetExportable Export Columns Options labels and type #1672

Open Yamit Amaya opened this topic on on Oct 19, 2020 - 2 comments

Yamit Amaya commented on Oct 19, 2020

Hi to forum,

I have a problem o doubt with BigSpreadsheetExportable, in the example I can specify the colums that I want to export, but the example parameter is a unidimensional array with index of columns:

from the documentation: https://www.koolreport.com/docs/excel/export_to_big_spreadsheet/

<?php
$report = new MyReport;
$report->run()->exportToXLSX(array(
    "dataStores" => array(
        'salesReport' => array(
            "columns"=>array(
                0, 1, 2, 'column3', 'column4' //if not specifying, all columns are exported
            )
        )
    )
))->toBrowser("myreport.xlsx");


But I need to give the option to specify the label and type of the columns because in datetime and decimal number are detecting as string and is not correct type.

I try with this like view but make a loop at export.

        if ($type === 'XLSX') {
            $report->run()->exportToXLSX(
                array(
                    "dataStores" => array(
                        'connectivity_test_results' => array(
                            "columns"=>array(
                                "fecha_ejecucion"=>array(
                                    "type"=>"timestamp",
                                    "label"=>"Fecha"
                                ),
                                "codigo_operador"=>array(
                                    "label"=>"Código Operador"
                                ),
                            )
                           
                        ),
                    ),

                )
            )
                ->toBrowser("ReportName.xlsx");

How i can make this ?

thanks in advance.

David Winterburn commented on Oct 20, 2020

Hi Yamit,

There're two solutions for setting column meta with exporting to excel or big spreadsheet. The first one is to set column meta in a report's setup like this:

//MyReport.php
->pipe(new ColumnMeta(array(
    "column1" => array(
        "label" => "Column 1",
        "type" => "number"
    )
)))
->pipe($this->dataStore("myDs"));

The second one is to set column meta in excel's Table widget in excel export template:

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

https://www.koolreport.com/docs/excel/export_to_big_spreadsheet/#spreadsheet-export-template

Please try this and let us know how it works for you. Thanks!

Yamit Amaya commented on Oct 23, 2020

Hi David,

thanks for your answer, I test the first option and work partially because take the column label, but the type not, i try to set datetime and number for fractional numbers but not work, unless i'm doing something wrong setting the type:

$this->src('pgsql_sigma')
            ->query("SELECT r.fecha_ejecucion,z.codigo_operador,z.id_beneficiario_mintic,
                            z.departamento,z.municipio,z.centro_poblado,
                            r.bw_down, r.bw_up,
                            r.anio_ejecucion,r.mes_ejecucion,r.dia_ejecucion,r.hora_ejecucion                                                   
                     FROM connectivity_test_results r join zonas z on z.id = r.zona_id ")
             ->pipe(new ColumnMeta(array(
                 "fecha_ejecucion" => array(
                     "label" => "Fecha Ejecución",
                     "type" => "datetime"
                 )
                 ,
                 
                 "bw_down" => array(
                     "label" => "Download",
                     "type" => "number"
                 ),
                 "bw_up" => array(
                     "label" => "Upload",
                     "type" => "number"
                 ),

I'm going to try the second option and tell you.

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
solved

None