I know CSV

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.

  • There is no official content type for CSV.

  • IE doesn’t seem to care about content types much if you specify csv as the file extension.

  • You can override the filename of dynamic content by setting 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.

  • 3 thoughts on “I know CSV”

    1. 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.

    Leave a Reply

    Your email address will not be published. Required fields are marked *