Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my csv file open in a browser window and not in Excel - only in Safari

Is there something special I need to know to get my csv file to open automatically in Excel when downloading with Safari (5.1)? At the moment it opens in a browser window, which doesn't happen in any other major browser, so I'm not sure if it's a browser setting or a proper bug that I need to fix.

I'm adding headers like so:

Response.AddHeader("content-disposition:", "attachment;filename=exportglossary.csv");
Response.ContentType = "text/csv";

I have had a brief look through the browser settings in Safari and can't see anything that looks to me like it would obviously fix this.

I have seen that I can add:

header("Content-type: application/vnd.ms-excel")

instead of text/csv, but as it works in all other browsers I would rather not change it.

Thanks :)

like image 796
Kai Avatar asked Sep 01 '25 01:09

Kai


1 Answers

It's definitly because of Content-Type. I used to have the same problem. using this solved my problem

response.setHeader("Content-Type","application/ms-excel");

and it's work perfectly fine in all browsers

like image 108
Sima Avatar answered Sep 03 '25 22:09

Sima