6

i am currently encountering an issue where I'd like to put a link to a shared excel sheet in our intranet. Unfortunately the normal href="http:..." link automatically opens and saves it to the local machine instead of enabling the work on the shared sheet which is on the server itself.

I have read through here a bit and found solutions like : file://///SERVER/PATH/Excel.xls but sadly that solution doesn't do anything.

If its relevant: my server version is Windows Server 2012

noa-dev
  • 3,561
  • 9
  • 34
  • 72

3 Answers3

10

You can tell browser to open with Excel (if installed) by adding ms-excel:ofe|u| in front of your Excel file Url.

<a href="ms-excel:ofe|u|http:...xls">Open in Excel</a> 
user916867
  • 109
  • 1
  • 3
  • 1
    I cannot run it localy - excel throws "can't find a file..." (directory is 100% accurate, file is in the same folder as index.html). Is this design to work only via http? – Rafał Mar 18 '19 at 13:44
  • Is it possible to open an OData data source in Excel in that fashion? – gtu Mar 18 '21 at 20:34
8

HTTP is a stateless protocol. What that means for you is that when your users download a file from the intranet via http, they are downloading a copy, rather than the original. Any changes they make will only appear in their copy, and then you end up with loads of copies of the same workbook with different, possibly overlapping changes. You don't want that!

And also ... how are your users even going to upload their changes?

You need to create a shared folder on your network and put the workbook there. You can then use the file:///SERVER/PATH/FILE.xls format in your <a /> links on your intranet to direct your user to the actual file on the server.


I would recommend you start by creating a simple html doc on your desktop to get familiar with the file:/// path format. Eg

<html>
    <head />
    <body>
        <a href="file:///SERVER/PATH/FILE.xls">Click</a>
    <body>
 <html>

save that in notepad and rename the extension from .txt to .html.

You can also type file:/// paths straight into windows explorer's address bar which allow for testing paths without resorting to the html document mentioned above.

UNFORTUNATELY! It seems that the browsers default behavior is to always download a link rather than open it (even if it is a local resource), so if you actually want to open it then you must resort to changing your browser intranet permissions to allow JS to access local resources, which then allows you to use the technique below.


This article (http://www.codeproject.com/Articles/113678/How-to-execute-a-Local-File-using-HTML-Application) uses

<script type="text/javascript" language="javascript">
    function RunFile() {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
    }
</script>

to open notepad. You can use command line arguments with Excel.exe (https://support.office.com/en-za/article/Command-line-switches-for-Excel-321cf55a-ace4-40b3-9082-53bd4bc10725) to tell it what the file path is...

Excel.exe "C:\PATH\Excel.xls"
  • Thank you for your detailed reply. I have tried that already and it didn't work - allthough i forgot to check if there are any console logs to that error. I happen to get the following output in the console : Not allowed to load local resource: file:///SQL/inetpub/wwwroot/tabellen/omv/2015-OMV-Anmeldung.xls Which is werid to me since all users have the right to access and alter the file – noa-dev Jul 17 '15 at 09:48
  • Don't put the file inside your website file structure! Put it in another folder that has noting to do with your website and share that. Managing permissions is bad enough with bringing IIS into the picture! – 3-14159265358979323846264 Jul 17 '15 at 09:51
  • created a folder outside of my website architecture and shared it to everyone - same result : everyone can access it manually but clicking the link prints out the same error – noa-dev Jul 17 '15 at 09:59
  • Ok. You should do that anyway :0)! But it could also be the security permissions within your browser ... actually this has more relevant information ... http://stackoverflow.com/questions/5074680/chrome-safari-errornot-allowed-to-load-local-resource-file-d-css-style – 3-14159265358979323846264 Jul 17 '15 at 10:02
  • 1
    Have you tried copying the file to your local machine, and then doing something like `file:///c:/Excel.xls`? That way you can find out if it's the network, or the browser causing the problem. – 3-14159265358979323846264 Jul 17 '15 at 10:09
  • Now i did :) - localy the file gets downloaded when I click the link, the error doesnt occur. But i dont want to download the file either. Id want the user to be able to OPEN the shared excel file, work in it and save it so that the changes will all be made in one file and not every1 having their own file – noa-dev Jul 17 '15 at 10:19
  • Have a look here ... http://stackoverflow.com/questions/5615321/is-it-possible-to-open-an-excel-file-in-its-current-location-not-download-it ... and here ... http://superuser.com/questions/676087/force-ie-to-open-local-files-in-the-intranet-zone-trusted-sites ... it seems you may have to jump through some hoops. One way i can think of, assuming you allow intranet js to run and access local resources would be a link that runs a script that opens the file. It seems that downloading by default is deliberate to protect users. – 3-14159265358979323846264 Jul 17 '15 at 10:41
  • 1
    Updated my answer to show how to do this via scripting. – 3-14159265358979323846264 Jul 17 '15 at 10:46
2

Use the below link if you are trying to open local file in excel.

<a href="ms-excel:ofe|u|file:///d:/folder/aaa.xlsx">Open in Excel</a>

Note: The file path should have forward slash