Create hyperlink to CSV File and use application to open file

I have a link which points to a CSV file. When clicked, it opens the file in the browser. I would like to use a different application (ie Excel, Open Office, Lotus) to open the file as a spreadsheet. Is it possible to include headers or something to make this happen? Thanks

Link:

<a target="_blank" href="contacts.csv">Contacts</a>

Browser Displays:

First Name,Last Name,Title,Email,Company,Address,City,State,Zipcode,Direct Phone,Mobile Phone,Direct Fax,Company Phone,Company Fax
John,Doe,Estimator,johnd@acme.com,Acme Co.,112 Main St,Gothem,IL,,(847) 555-1122,,,,
Jane,Doe,Engineer,,Ace Industries,,Seattle,WA,,,,,(206) 555-1234,

You will need to set the content type header on whatever generates the csv file.

See: Setting mime type for excel document

For the available headers.

You don't say which language you're using to generate the csv data, or whether it's simply a flat file you're linking to. While most languages will provide the means to set headers on the fly, if you are using static flat files, you may need to set your htaccess (assuming apache is your web server). There are instructions for that case here: http://htaccess.wordpress.com/2008/07/16/sending-correct-content-type-headers-with-htaccess/


The answer that @stakolee links to is really more specific to opening a file in Excel. If you want to be correct and widely compatible, the mime type should be for CSV, not Excel.


The correct mime type is text/csv . Excel will likely be the application associated with this type, so you'll get the behavior you want.

What MIME type should I use for CSV?


You cam also set Content-Disposition to help things along.

Content-Disposition: attachment; filename="filename.csv"

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


If you want backup options, you can set multiple mime types.

text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel

Filepicker does not accept mimetype 'text/csv' on windows


RFC 4180 says you can respond with text/csv; header=present text/csv; header=present or header=absent to indicate if the files contains column headers.

Proper syntax for optional header parameter for text/csv mimetype?

链接地址: http://www.djcxy.com/p/46842.html

上一篇: 如何从java jsp javascript打开excel?

下一篇: 创建超链接到CSV文件并使用应用程序打开文件