I am unable to export quoted values for a field. The CSV export removes al quotes. For example (what I need):

"<items><item id=""001""/></items>";Company;name@name.com

But the output will be:

<items><item id=001/></items>;Company;name@name.com

So all quotes are removed.

If I select the option "Quote values. Useful for output that might contain your separator as part of one of the values." then all the values will be quoted and that's not what I'm looking for.


#2 views_data_export-the-csv-export-removes-2056343-2.patch2.32 KBSteven Jones
PASSED: [[SimpleTest]]: [MySQL] 92 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


Steven Jones’s picture

Title: The CSV export removes al quotes » The CSV export removes all quotes
Version: 7.x-3.0-beta6 » 7.x-3.x-dev

I suspect that you need to run the dev version, and you need to use the 'Keep HTML tags' option. I've got some tests that I'll beef up to make sure that attributes are handled correctly.

Steven Jones’s picture

Status: Active » Needs review
2.32 KB
PASSED: [[SimpleTest]]: [MySQL] 92 pass(es). View

Beefed up the HTML tests

Steven Jones’s picture

Status: Needs review » Fixed

Pushed that change to the tests into 7.x-3.x

L5’s picture

Thanks! The 7.x-3.x-dev (2013-Aug-06) seems to work with single quotes. But it still removes double quotes.

Steven Jones’s picture

Could you provide an example test case please?

What exactly are you expecting and what is output?

L5’s picture

I need an export to CSV. I'm using Views data export 7.x-3.x-dev (2013-Aug-06). The view has two fields. Let's say email and items. The field email doesn't use any html tags. The field items does use html tags.

For the items output I use a field "Global: custom text" and give it a value. I want to use some XML code like:

"<items><item id=""001""/></items>"

The output will be:


So there is no value for items. I expect the output would be:

name@name.com;"<items><item id=""001""/></items>"

If I change the items field to "Global: PHP" (using https://drupal.org/project/views_php) and give it an output like:

echo '"<items><item id=""001""/></items>"';

The output will be (even if I escape the double quotes):

name@name.com;<items><item id=001/></items>

So all double quotes are removed, but the XML code is displayed. I would expect:

name@name.com;"<items><item id=""001""/></items>"

I hope my example is clear enough?

Steven Jones’s picture

You will need to use the 'Quote values' option to get the correct quotes added in the output.

L5’s picture

Yes, but with the 'Quote values' option I will have the following output:

"name@name.com";""<items><item id=""001""/></items>""

So al values are quoted. In this case the proper solution should have an output with only the XML quoted, like:

name@name.com;"<items><item id=""001""/></items>"
Steven Jones’s picture

Why does that matter?

I understand that it adds a lot of unnecessary quotes, but is that really a problem?

L5’s picture

That was my first thought too. The exported CSV is used for an import to Parcelware (PostNL). Their software is refusing a file with unnecessary quotes, only the XML part is allowed to use double quotes. So in this case it's a problem.

Steven Jones’s picture

Title: The CSV export removes all quotes » Allow quoting specific CSV fields
Category: support » feature
Status: Fixed » Active


I hate the fact that CSV isn't a standard at all!

Okay, so you want to be able to quote by specific fields, fair enough.

L5’s picture

Yes, that's probably a better title / description. :)

  • Steven Jones committed bb11be0 on 7.x-4.x
    Issue #2056343 by Steven Jones | LAN5: The CSV export removes all quotes...
cotillardq’s picture

Issue summary: View changes

Did you ever found a solution for this? I have the same issue where I only need to quote certain fields.

cotillardq’s picture

Ok this is how I solved it. Not very clean but it works.

in /modules/views_data_export/theme/views_data_export.theme.inc
replaced line 181
$vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
$output = str_replace('\"', "%%", $output);
$output = $wrap . str_replace('"', $replace_value, $output) . $wrap;
$vars['themed_rows'][$i][$j] = str_replace('%%', '"', $output);