KoolReport's Forum

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

CSV Export #816

Open BDO India LLP opened this topic on on Apr 18, 2019 - 3 comments

BDO India LLP commented on Apr 18, 2019

Hello,

How can I escape "," in value while generating csv from an array?   Suppose I have following php array

<?php

$arr = [

    ["name" => "John Doe", "email" => "johndoe@nomail.com"],

    ["name" => "Foo, Bar", "email" => "foobar@nomail.com"]

];

?>

In generated CSV, "John Doe" is taking single cell, but "Foo, Bar" taking two cells. How can I prevent this, so my second value will fit in a single cell.

Please refer following image

KoolReport commented on Apr 18, 2019

If you try:

["name" => "Foo\, Bar", "email" => "foobar@nomail.com"]

does it works?

BDO India LLP commented on Apr 18, 2019

Tried it already but did not worked

David Winterburn commented on Apr 22, 2019

Hi,

In case your column data has the comma character, we'd suggest you use other character (such as semicolon-";") as delimiter for columns. Please test export code like this:

$report->run()->exportToCSV(array(
        'dataStores' => array(
            'salesCustomer' => array(
                'delimiter' => ';'
            )
        )
    ))

When you import the exported file to excel or other programs, just use the delimiter character to separate columns instead of using the standard comma. Thanks!

Edit: even if your column data has both comma and semicolon, you are free to choose any sequence of character (such as "-||-") for delimiter.

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

Export