How to open, edit, and create Office doc_javascript on a web page

Source: Internet
Author: User
How to open, edit, and create an Office document on a Web page how to open, edit, and create an Office document on a web page
Word is opened in IE at the link of idea document. Many people may be interested in this question. therefore, write a blog to give a rough description of the method.

After Office2003 is installed, an ActiveX control is installed in the system, which 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 open and edit Office documents. (In addition, Office XP should already contain this ActiveX control .)

First, use a Script to create a local object:

OpenDocObj = new ActiveXObject ("SharePoint. OpenDocuments.2"); // to be compatible with Office XP, you can create "SharePoint. OpenDocuments.1"

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

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

The opendocobjobject uses different officedocument (.doc).xls0000.ppt) to open different programs (Word, Excel, and PowerPoint ). The ViewDocument () method also has an overload signature, which allows us to manually specify which program to activate to open the document:

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

How do I open the Office program and edit files online?

OpenDocObj. EditDocument ("http://www.abc.com/documents/sample.doc ");

You can directly activate Word, edit the document in Word, and then click save in Word to save the file to the server. Note: In order for Word to directly save the edited document to the server, the Windows Identity in the current context of the Web site must be in the corresponding directory of the server (that is, the physical path on the server corresponding to the virtual directory "http://www.abc.com/documents.pdf) you have the write permission. Otherwise, the Save action fails. After editing, EditDocument () returns a bool value to indicate whether the editing operation is successful.

We can also open a document template on the server to create a new document:

OpenDocObj. CreateNewDocument ("http://www.abc.com/documents/sampleTemplate.dot", "http://www.abc.com/documents ");

You can use /". The program used to create a new document depends on the template file type (for example, the. dot template corresponds to the Word ). You also need to pay attention to permissions when saving new documents. The CreateNewDocument () method returns a bool value to indicate whether the operation is successful.

The first parameter of the CreateNewDocument () method, in addition to using a template address, can also be directly specified as the ProgID of the client program 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.