Open excel file through normal html link

烈酒焚心 提交于 2019-11-28 04:07:36

问题


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


回答1:


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"



回答2:


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> 


来源:https://stackoverflow.com/questions/31472397/open-excel-file-through-normal-html-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!