Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get a spreadsheet to open Excel instead of a browser window?

If you call javascript window.open and pass a url to a .xls file it open on some machines in the browser window. How can you force it into Excel?

like image 472
pappes Avatar asked Sep 23 '08 12:09

pappes


People also ask

How do I stop Excel from opening in browser?

Open "My Computer" and select "Folder Options" under the "View" menu. Select the "File Types" tab and find the icon that says Microsoft Excel Worksheet in the Registered File types. Check the box in the new window that says "Confirm open after download".

How do you open in Excel instead of Excel online?

Select Open in Desktop App at the top of your workbook. If you don't see it, there should be a search bar along the top of your workbook. In that search bar, type open, and then select Open in Desktop App.


2 Answers

Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.

And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.

It's best to just link to the document with <a href="foo.xls">. And provided your server is sending a mime-type of application/x-excel or application/x-msexcel this will almost always nudge the browser into opening a new window with the Excel document.

like image 142
pcorcoran Avatar answered Sep 21 '22 20:09

pcorcoran


If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:

application/vnd.ms-excel    xls

I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.

like image 30
MB. Avatar answered Sep 23 '22 20:09

MB.