Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open excel file through normal html link

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

like image 453
noa-dev Avatar asked Jul 17 '15 09:07

noa-dev


3 Answers

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> 
like image 87
user916867 Avatar answered Nov 13 '22 19:11

user916867


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"
like image 8
3-14159265358979323846264 Avatar answered Nov 13 '22 17:11

3-14159265358979323846264


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

like image 2
Shanmuga Prasad Thangamuthu Avatar answered Nov 13 '22 17:11

Shanmuga Prasad Thangamuthu