通过普通的html链接打开excel文件 [英] Open excel file through normal html link

查看:166
本文介绍了通过普通的html链接打开excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

If its relevant: my server version is Windows Server 2012

推荐答案

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

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?

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

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.

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

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>

将其保存在记事本中并将扩展名从 .txt 重命名为 .html.

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

您也可以直接在 windows 资源管理器的地址栏中键入 file:/// 路径,这样就可以测试路径,而无需求助于上述 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.

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

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.

本文(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>

打开记事本.您可以在 Excel.exe 中使用命令行参数 (https://support.office.com/en-za/article/Command-line-switches-for-Excel-321cf55a-ace4-40b3-9082-53bd4bc10725) 告诉它的文件路径是什么...

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:PATHExcel.xls"

这篇关于通过普通的html链接打开excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆