I have been spending (wasting?) my time trying to stream dynamically generated CSV content straight into Excel from a browser.
Things I wish I had known at the start.
Content-Disposition: attachment; filename="blah.csv"
as a header.
Still, got it working eventually, and I’m happier for being able to say I know how to do it now.
Is there actually a standard for CSV? I mean, we all know how CSV works, but is there a specification for it, or is it just folk law?
If there *is* a spec, it is online anywhere?
Good point, I just made it up as I went along. 🙂
I’m working on a CSV export system for our corporate website at the moment.
Getting a CSV format that works in Word, Access 97, Access 2000, Excel and a few others is a REAL juggling act. What works in one, doesnt always work in the other :-/
I ended up with the following rules which seem to work:
Always quote strings and dates
Always export your dates in the format "dd mmm yyyy" (17 MAY 1968)
Always terminate each line (record) with an rn pair
Always make sure each record has the same number of fields – even if you have to add empty ones to the end.
As a side note: Make sure you switch on server side compression (mod_deflate for apache) on your web server for your CSV files. They usually compress up very well in deed.