2

I am using HTML. I have placed an XLSX file in my file system and gave a link in HTML file through anchor tag as below.

<a class="someClass" href="SampleFile.xlsx" target="_blank" type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">DownloadFile</a>

But the problem is it does not work in IE. in IE xlsx file is downloaded as Zip file than xlsx file. But in firefox it works as intended.

in IE:

enter image description here

in FF:

enter image description here

How can i tell IE to download the file as xlsx file rather than zip file?

Thanks!

Spudley
  • 166,037
  • 39
  • 233
  • 307
user755806
  • 6,565
  • 27
  • 106
  • 153

1 Answers1

3

You will need to set the correct "content type" and/or "content disposition" headers on the server.

You can't do this reliably for Internet Explorer in HTML alone, but you you can do it server side (e.g. with PHP, ASP, or whatever it supports) or by configuring the web server the file is hosted on (e.g. Apache or IIS) to return the appropriate headers for all files with the given extension.

See this answer for some insight: Setting mime type for excel document

Note: Because Internet Explorer exposes settings that override this behaviour, and different versions of Internet Explorer and Microsoft Office respond differently to some headers by default, you might find it always behaves a bit unreliably, even when you set the headings on the server. I've encountered different browser behaviour on corporate PC's at the same organisation with the same operating system and the same version of Internet Explorer and Microsoft Office, but was unable to find the root cause of the different behaviour (e.g. downloading vs. opening actually inside the browser vs. opening in the application) Other other browsers at least seem to behave consistently.

Community
  • 1
  • 1
Iain Collins
  • 6,774
  • 3
  • 43
  • 43
  • NB: I say "and/or" as there are multiple ways to do this (depending on if you want the document to always be download, to open up in the existing browser window, or to open in a new Excel window). Personally I would try setting an appropriate content type first, by configuring the web server to recognise the file extension as being for Excel. – Iain Collins Jul 02 '13 at 09:52