Posted by CasaDelGato on October 17, 2009 at 8:17pm
| Project: | Views Bonus Pack |
| Version: | 6.x-1.0 |
| Component: | Views Export |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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","
"
Comments
#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.
#12
Ive a project need to export views data to csv format.
And I tried and got the same issue mentioned by CasaDelGato.
#13
I really can't do much with this until someone can help me reproduce it. It really shouldn't have anything to do with views bonus pack though. I'm not going to trim field values.
Here's an example csv export: http://views.nerdpalace.net/export_example/csv
My best suggestion is to please look at your theme and make sure its not affecting your output.
#14
It's happening for me with the Garland them, which is one of the basic themes.
Any chance you've customized YOUR theme in such a way that this problem doesn't happen?
#15
Yup, yours doesn't have a newline at the start of each value inside the double quotes.
I did post my views definition, I'll have to assume that didn't help.
What else can I do to help find the problem?
Or would it be possible to add a "trim whitespace" option to the configuration options?
#16
I also needed this functionality recently for a site using some advanced views/theming tricks such as views fields generated using additional displays included using views_embed_view(). Not to get into the details of my data structure, but the simplest way to deal with this was to add an option to call trim() after the calls to strip_tags() and decode_entities() in template_preprocess_views_bonus(). I understand this views bonus shouldn't simply clobber rendered fields without warning, so I created a simple option (off by default) to trim whitespace for users who would like this shortcut to potentially overriding half a dozen default views templates. Patch for 6.x-1.0 attached.
#17
Very cool! Modifed the patch slightly to repeat a little less and apply to the new functions in views_bonus_export.theme.inc but otherwise great patch!
#18
Automatically closed -- issue fixed for 2 weeks with no activity.