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.
我的应用程序允许用户将其数据下载为CSV文件。这些应该在电子表格应用程序中打开。在Linux系统上,我被正确地提示打开OpenOffice,但我的一些用户抱怨说,当他们下载文件时,它不会自动打开Excel,而是要求他们选择应用程序。当他们从其他网站下载CSV时,它会在Excel中正确打开。
I am setting:
mimetype: text/csv
content_disposition: attachment; filename.csv
我正在设置:mimetype:text / csv content_disposition:attachment; filename.csv
1 个解决方案
#1
63
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.
在Windows浏览器中,在下载文件后将忽略MIME类型,并且仅使用文件扩展名来确定相应的应用程序。
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.
此外,正确地在Excel中打开.CSV文件很困难,因为默认分隔符取自打开CSV的计算机上的区域设置。此外,编码不是从文件内容或MIME类型确定的,因此任何非ASCII字符都难以工作。
#1
63
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.
在Windows浏览器中,在下载文件后将忽略MIME类型,并且仅使用文件扩展名来确定相应的应用程序。
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.
此外,正确地在Excel中打开.CSV文件很困难,因为默认分隔符取自打开CSV的计算机上的区域设置。此外,编码不是从文件内容或MIME类型确定的,因此任何非ASCII字符都难以工作。