0

I have a CSV file thats been hyperlinked. When the user clicks it, its supposed to open in a XLS file but for some reason its opening in HTML page..How can I fix it?

The python bottle application runs on apache webserver.

<a id="d14" href="../files/BUY_PRODUCT_LIST.csv">PRODUCT_LIST.csv</a><br>
user1050619
  • 19,822
  • 85
  • 237
  • 413
  • csv is probably being served up as text/plain. you'd have to serve it up with an appropriate excel mime type, e.g. http://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document – Marc B Sep 05 '14 at 19:28

2 Answers2

1
  1. Assuming this to be a link to a static .csv file that is directly linked, you can modify the mime types definitions on your webserver to set the Content-Type header for csv as ms-xl file type.

    If you are using apache webserver , edit the mime.types file to add the following line:

    application/vnd.ms-excel csv

    of-course then all .csv files would be opened by default in the MS-Excel app.

2.If the file is dynamically generated , then set the response header 'Content-Type:application/vnd.ms-excel' in your server side code.

vreddy
  • 173
  • 1
  • 9
0

You're confusing a Microsoft Excel spreadsheet, .xls with a comma separated value file, .csv.

csv is just a text file in which tabular data is delimited by a comma (or a tab, a dot, a semicolon, etc). Your browser can handle this file type as a text file and will display it as such.

You will have to modify the HTTP header and change the Content-Type to something more fitting.

msvalkon
  • 11,887
  • 2
  • 42
  • 38