CSV export is adding a newline after the first double quote of EVERY value.
CasaDelGato - October 17, 2009 - 20:17
| Project: | Views Bonus Pack |
| Version: | 6.x-1.0-beta4 |
| Component: | Views Export |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Description
The generated .csv file looks like this: (ONE row of data shown)
"
Expired","
Jon","
","
Allen","
28103 11th Ave E","
","
Roy","
WA","
98580","
","
seattletacomaanimalrescue@msn.com","
","
","
2008-11-01","
"

#1
So, nobody else is using CSV export?
#2
Nobody else is having this problem. I'd look closer at how the fields are themed.
#3
Well, this is happening on 2 different sites, using 2 different theme.
Garland on one, Marinelli/Giordani on the other.
Seems like the base CSV export code should work with Garland, since that is a default theme.
You are probably right about the themeing though. I took a look at the page source for the view, and it appears that every single value starts with a newline character.
Shouldn't the CSV export be trimming whitespace off values before adding them to the file?
#4
And, while thinking about that, I took a look at the views export CSV source code.
Note that I have NEVER worked with PHP before, but as far as I can tell it's just another language with some cryptic syntax.
So, in views_bonus/export/views_bonus_export.theme.inc
I changed line 31 from this:
$vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, decode_entities(strip_tags($value))) . $wrap;to this:
$vars['themed_rows'][$i][$j] = $wrap . trim(str_replace('"', $replace_value, decode_entities(strip_tags($value)))) . $wrap;And now it works!
Guess I'll have to figure out how to sign up as a developer so I can submit changes.
#5
That would be fine if it didn't remove strings people wanted to have as part of their export. What I actually meant was check the formatting option you've chosen or theme functions.
#6
I'm not sure what you mean by "check the formatting option you've chosen or theme functions".
As far as I can tell, I've never seen a "add linefeed before every field value" checkbox anywhere.
This is happening with Garland theme, and I haven't seen any settings that look like they would cause this.
Neither do I see any settings in the Views panels that might cause this.
Now, it's quite possible that there is some obscure interaction with some other module, but finding that could take days (if it even exists).
As for my suggested change, in a .CSV file, you do NOT want newlines or whitespace around your values, as it causes many programs to fail. (like MS Excel)
And my change only affects .CSV output, none of the other choices.
#7
%Smartass mode% My excel don't have any problem with extra whitespaces in csv-files.%% But let's not discuss that.
The options to check I guess are the options of your view, and more specifically of the fields in the view.
Perhaps you could export the view and paste it here?
What other modules do you have to interfere with your views/values?
I'm thinking you have a rare combination as you're the only one reporting this problem.
#8
Hmm, my MS Excel chokes on newlines at the start of each value. (not choke exactly, just looses the data)
Anyway, Views modules installed & enabled are:
Bonus Views Export
Mailing labels
Views
Views Slideshow
Views UI
I've attached the exported view.
#9
One question that just popped into my head. (rare occurrence there, thought that is...)
Why is the field data being Themed for .CSV output?
Since all formatting and such is stripped back off, why not just use the raw field data?
#10
Its important that it go through views themeing because that's where things like trimming and stuff happen. If it where not themed you would likely not ever have the data you expected. Also, many times this is where string formatting happens so not doing it would mean possible security problems.
#11
Ok, but I would argue the point about "trimming". I still have the problem where EVERY field gets a newline tacked on the start of the value, inside the double quotes.