Html 通过普通的html链接打开excel文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31472397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:48:19  来源:igfitidea点击:

Open excel file through normal html link

htmlexcelhyperlinkwindows-server-2012-r2

提问by noa-dev

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.

我目前遇到一个问题,我想在我们的 Intranet 中放置一个指向共享 Excel 工作表的链接。不幸的是,普通href="http:..."链接会自动打开并将其保存到本地机器,而不是在服务器本身的共享工作表上启用工作。

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

我在这里通读了一下,找到了类似的解决方案:file://///SERVER/PATH/Excel.xls但遗憾的是,该解决方案没有任何作用。

If its relevant: my server version is Windows Server 2012

如果相关:我的服务器版本是 Windows Server 2012

回答by user916867

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

您可以通过添加ms-excel:ofe|u|告诉浏览器使用 Excel(如果已安装)打开 在您的 Excel 文件 Url 前面。

<a href="ms-excel:ofe|u|http:...xls">Open in Excel</a> 

回答by 3-14159265358979323846264

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!

HTTP 是一种无状态协议。这对您来说意味着当您的用户通过 http 从 Intranet 下载文件时,他们正在下载副本,而不是原始文件。他们所做的任何更改只会出现在他们的副本中,然后您最终会得到相同工作簿的大量副本,其中包含不同的、可能重叠的更改。你不想那样!

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.xlsformat in your <a />links on your intranet to direct your user to the actual file on the server.

您需要在网络上创建一个共享文件夹并将工作簿放在那里。然后,您可以使用Intranet 上链接中的file:///SERVER/PATH/FILE.xls格式<a />将您的用户定向到服务器上的实际文件。



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

我建议您首先在桌面上创建一个简单的 html 文档以熟悉file:///路径格式。例如

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

save that in notepad and rename the extension from .txtto .html.

保存在记事本中,并重新命名从扩展.txt.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.

您还可以file:///直接在 Windows 资源管理器的地址栏中键入路径,这样就可以在不求助于上述 html 文档的情况下测试路径。

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.

不幸的是!似乎浏览器的默认行为是总是下载链接而不是打开它(即使它是本地资源),所以如果你真的想打开它那么你必须求助于改变你的浏览器内网权限以允许 JS 访问本地资源,然后允许您使用以下技术。



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

这篇文章(http://www.codeproject.com/Articles/113678/How-to-execute-a-Local-File-using-HTML-Application)使用

<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 中使用命令行参数(https://support.office.com/en-za/article/Command-line-switches-for-Excel-321cf55a-ace4-40b3-9082-53bd4bc10725)告诉它文件路径是什么...

Excel.exe "C:\PATH\Excel.xls"