How to create a HTML link which forces MS Word to

2019-01-16 10:38发布

问题:

Let's suppose that I have WebDAV-enabled server, where I have bunch of Office documents. I'd like to generate webpage which has link to document such that clicking on the link will open Microsoft Word. Word will in turn download document from WebDAV server, and when user finishes editing document, MS Word will upload it back.

I know that MS Word (and other Office programs) support editing of documents stored on WebDAV server. What I don't know, is how to generate link which will trigger MS Word to download this document by itself.

Is it possible? Maybe using some special scheme?

回答1:

As far as I recall, the only way to achieve this is to explicitly instantiate Word through ActiveX, and the pass it the URL to open.

This can be done inside the HTML page (in which it'll need IE), or using an external application that then would need to be registered for a new mime type (see http://greenbytes.de/tech/webdav/rfc4709.html#rfc.section.B.1 for an example).



回答2:

Ummm, you could also use something like this:

<a href="ms-word:ofe|u|http://some_WebDav_enabled_address.com/some_Word_document.docx">Open Document in Word</a>

The difference from the above answers is that this would no longer require ActiveX and it will work at least in IE 8+, Chrome and Firefox, as long as it is opened from a Windows machine, for Office 2010+ (not 100% sure about this one though).

Explanation: the ms-word:ofe part is a protocol that gets installed on the client machine when Office is installed. I don't know exactly what the |u| part does.



回答3:

Confluence uses the EditDocument method of the SharePoint.OpenDocuments ActiveX control.

Example in Javascript:

new ActiveXObject("SharePoint.OpenDocuments.1").EditDocument("http://example.com/test.doc")


回答4:

I found that Confluence can do this. They have special Firefox plugin, but it should work fine with Internet Explorer.

  • Editing a Confluence Page in an Office Application
  • Installing the Firefox Add-on for the OFfice Connector

In fact, when I started to play with it, it turned out that IE does actually opening document directly from WebDAV. It seems like if IE downloaded the page, passed it to MS Word, but together with URL. MS Word can then save file back (well, sometimes it sees the file as read-only, and doesn't allow to save back, but allows to upload under different name).

Still investigating.