How to open, edit, and create Office documents directly on a Web page _javascript tips

Source: Internet
Author: User
How to open, edit, and create Office documents directly on a Web page
A friend asks how to do this on a Web page, as it does in SharePoint, to activate a client's word to open a. doc file, instead of just clicking the. doc link when Word is opened in IE. Think of this problem should be a lot of people will be interested, so simply write a blog to roughly describe the method.

After installing Office2003, an ActiveX control is installed on the system, which is located in the Program Files\Microsoft Office\office11\owssupp.dll. This control enables JavaScript on the client page to activate the local office software to open and edit Office documents. (another, Office XP should already contain this ActiveX control.) )

First, create a local object with script:

Opendocobj = new ActiveXObject ("Sharepoint.opendocuments.2"); To be compatible with Office XP, you can create "Sharepoint.opendocuments.1"

Then, invoke the corresponding method of the opendocobj. For example, open an Office document on the server:

Opendocobj.viewdocument ("Http://www.abc.com/documents/sample.doc");

The Opendocobj object opens different programs (Word, Excel, PowerPoint) based on the different Office document types (. doc,. xls,. ppt) in the parameter. The ViewDocument () method also has an overloaded signature, which 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 about opening Office programs to edit files online?

Opendocobj.editdocument ("Http://www.abc.com/documents/sample.doc");

You can directly activate Word, edit the document in Word, and then directly click on the Save function in Word, you can save the file to the server. Note: In order for Word to save the edited document directly to the server, Windows identity that accesses the current context of the Web site must have a corresponding directory for the server (that is, "http://www.abc.com/documents" The physical path on the server for this virtual directory has the appropriate write permission, otherwise the Save action will fail. When the edit is complete, editdocument () returns a bool value to reflect the success of the edit operation.

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 Http://www.abc.com/documents/sampleTemplate.dot template to create a new document, where the default new document is saved as "http://www.abc.com/documents/." The program that you use when you create a new document depends on the type of template file (for example, the. dot template corresponds to Word). The preservation of new documents also requires attention to permissions issues. The CreateNewDocument () method also returns a bool value to reflect the success of the operation.

The first parameter of the CreateNewDocument () method, in addition to the address of one template, can be directly specified as the ProgID of the client program that you want to use to create a new document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.