KoolReport's Forum

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

How change format value in export csv #2559

Open Anna Tolve opened this topic on on Feb 4, 2022 - 6 comments

Anna Tolve commented on Feb 4, 2022

Hello everyone, I export my report in csv with the following code:

<?php

    require_once "Report_1_1_1.php";
    $report = new Report_1_1_1;
    $report->run()->exportToCSV('result', array(
        'delimiter' => ';',
        "BOM"=>false,
    ))->toBrowser("Report_1.1.1.csv");

but i get format problems in the csv it generates:

I would like the first column representing a year to have no separators and the other numeric values to have the. as a separator of thousands and la, which separates the two decimal digits; furthermore, for some values such as the last column, I would also need to insert the suffix%. How can I achieve this?

KoolReport commented on Feb 7, 2022

Please consider to use XLSX to export percentage value and still maintain the value, if you exporting to CSV and want the % percent, the value will be in string.

Anna Tolve commented on Feb 7, 2022

I have already exported to xlsx, I am asked to do it also in csv, the main problem is to correctly format the digits with "." as a thousands separator and "," with two decimal places for percentage values. Is there a way to do it since unlike exporting in xlsx there is no .view file where to set the format but I directly export the query result set?

Sebastian Morales commented on Feb 7, 2022

Hi Anna, pls try to change the number column's meta before piping data to a datastore. Then export that datastore to csv. If it didn't work for you, pls post your report setup and export code for us to check it for you. Tks,

Anna Tolve commented on Feb 7, 2022

Hi Sebastian I don't understand what you want me to try... In this Report I don't use any calculated column but all the fields come from the query.

$this->src("data_base")
->query("	SELECT A.ANNO, T.TIPO, T.CATEGORIA...")
->params(array(":anno_selezionato"=>$this->params["anno"],
			":area_selezionata"=>$this->params["dettaglio"]))
->pipe($this->dataStore("result"));
Sebastian Morales commented on Feb 8, 2022

Pls try the ColumnMeta process:

$this->src("data_base")
->query("	SELECT A.ANNO, T.TIPO, T.CATEGORIA...")
->params(array(":anno_selezionato"=>$this->params["anno"],
			":area_selezionata"=>$this->params["dettaglio"]))
->pipe(new \koolreport\processes\ColumnMeta([
    "ANNO" => [
        "type" => "number",
        "decimals" => 2,
        "decimalPoint" => ",",
        "thousandSeparator" => "."
    ]
]))
->pipe($this->dataStore("result"));

Let us know how it works for you. Tks,

Anna Tolve commented on Feb 8, 2022

It works perfectly thank you very much Sebastian! ;)

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
solved

None