Open the WordExcel file directly in IE (reposted)

xiaoxiao2021-03-05  30

Some friends asked how to do the effects like SharePoint on the web page, can directly activate the client's Word to open the .doc file, not similar to directly click. Doc document link, Word is opened in IE. Think about this problem should be interested, so I simply write a blog to generally describe the method.

After installing Office2003, an ActiveX control is installed in the system, this control is located in "Program files / Microsoft Office / Office11 / Owssupp.dll". Through this control, JavaScript on the client page can activate the local Office software to implement open and edit Office documentation. (Other, Office XP should already contain this ActiveX control.)

First, create a local object with SCRIPT:

OpenDocobj = New ActiveXObject ("SharePoint.Opendocuments.2"); // You can create "SharePoint.Opendocuments.1" for compatibility with Office XP.

Then, the corresponding method of OpenDocobj is called. For example, open an Office document on the server:

OpenDocobj.ViewDocument ("http://www.abc.com/documents/sample.doc");

OpenDocobj objects open different programs (Word, Excel, PowerPoint) based on different Office document types (.doc, .xls ,.ppt) in parameters. The viewDocument () method also has a heavy-duty signature that allows us to manually specify which program is activated to open the document:

OpenDocobj.ViewDocument ("http://www.abc.com/documents/sample.doc", the progid of the program to be activated;

So what is the online editing of the Office program online?

OpenDocobj.editdocument ("http://www.abc.com/documents/sample.doc");

You can directly activate Word, edit your document in Word, then directly click the save function in Word, you can save the files on the server. Note: In order to let Word save the edited document directly to the server, the current context of the Web site must have the corresponding directory of the server (ie "http://www.abc.com/documents" virtual directory. The physical path on the corresponding server has the corresponding write permissions, otherwise the save action will fail. After the editing is complete, editdocument () will return a BOOL value to reflect whether the editing operation is successful.

We can also create a new document by opening a document template on the server:

OpenDocobj.createNewDocument ("http://www.abc.com/documents/sampletemplate.dot", "http://www.abc.com/documents/");

You can use the template of "http://www.abc.com/documents/sampletemplate.dot" to create a new document, the default new document is "http://www.abc.com/Documents/" . The program used when creating a new document depends on the type of the template file (such as a .dot template for Word). The saving of the new document also needs to pay attention to the issue. The CreateNewDocument () method also returns a BOOL value to reflect whether the operation is successful. The first parameter of the CreateNewDocument () method, in addition to the use of a template, you can also specify the progID of the client program that wants to create a new document.

转载请注明原文地址:https://www.9cbs.com/read-31924.html

New Post(0)