Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to set as mimetype for CSV files to open in spreadsheet applications

My application lets users download their data as CSV files. These are supposed to open in spreadsheet applications. On a Linux system, I get prompted correctly to open with OpenOffice, but some of my users complain that when they download the file, it does not open automatically Excel, but asks them to choose the application. When they download a CSV from some other site, it opens correctly in Excel.

I am setting:
mimetype: text/csv
content_disposition: attachment; filename.csv

like image 292
agiliq Avatar asked Sep 05 '09 06:09

agiliq


People also ask

What program should I use to open a CSV file?

Microsoft Excel is the most commonly used spreadsheet application for opening and editing CSV files. You can download a CSV file from many software programs.

What is the Mimetype of a file?

A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.


1 Answers

Try this:

Content-Type: text/csv; name="filename.csv" Content-Disposition: attachment; filename="filename.csv" 

In Windows browsers the MIME type is ignored after the file is downloaded and only file name extension is used to determine the corresponding application.

Also, making .CSV file open in Excel correctly is hard, because the default separator is taken from Regional settings on the machine on which the CSV is opened. Furthermore, the encoding is not determined from the file content or MIME type, so any non-ASCII characters are hard to get working.

like image 159
Filip Navara Avatar answered Oct 14 '22 05:10

Filip Navara