Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am unable to export quoted values for a field. The CSV export removes al quotes. For example (what I need):
items;company;email
"<items><item id=""001""/></items>";Company;name@name.com
But the output will be:
items;company;email
<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.
Anyone?
Comment | File | Size | Author |
---|---|---|---|
#2 | views_data_export-the-csv-export-removes-2056343-2.patch | 2.32 KB | Steven Jones |
Comments
Comment #1
Steven Jones CreditAttribution: Steven Jones commentedI 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.
Comment #2
Steven Jones CreditAttribution: Steven Jones commentedBeefed up the HTML tests
Comment #3
Steven Jones CreditAttribution: Steven Jones commentedPushed that change to the tests into 7.x-3.x
Comment #4
L5 CreditAttribution: L5 commentedThanks! The 7.x-3.x-dev (2013-Aug-06) seems to work with single quotes. But it still removes double quotes.
Comment #5
Steven Jones CreditAttribution: Steven Jones commentedCould you provide an example test case please?
What exactly are you expecting and what is output?
Comment #6
L5 CreditAttribution: L5 commentedI 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:
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):
So all double quotes are removed, but the XML code is displayed. I would expect:
I hope my example is clear enough?
Comment #7
Steven Jones CreditAttribution: Steven Jones commentedYou will need to use the 'Quote values' option to get the correct quotes added in the output.
Comment #8
L5 CreditAttribution: L5 commentedYes, but with the 'Quote values' option I will have the following output:
So al values are quoted. In this case the proper solution should have an output with only the XML quoted, like:
Comment #9
Steven Jones CreditAttribution: Steven Jones commentedWhy does that matter?
I understand that it adds a lot of unnecessary quotes, but is that really a problem?
Comment #10
L5 CreditAttribution: L5 commentedThat 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.
Comment #11
Steven Jones CreditAttribution: Steven Jones commentedUrgh.
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.
Comment #12
L5 CreditAttribution: L5 commentedYes, that's probably a better title / description. :)
Comment #14
cotillardq CreditAttribution: cotillardq commentedDid you ever found a solution for this? I have the same issue where I only need to quote certain fields.
Comment #15
cotillardq CreditAttribution: cotillardq commentedOk 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;
with
$output = str_replace('\"', "%%", $output);
$output = $wrap . str_replace('"', $replace_value, $output) . $wrap;
$vars['themed_rows'][$i][$j] = str_replace('%%', '"', $output);