How to Open Microsoft Excel, Word Application from Javascript

by Preetha 2012-09-14 22:48:57

Imagine opening a Word document or an Excel sheet from your script and controlling it from there. All this is possible via OLE Automation in Javascript - you can open Microsoft Office applications or any locally installed software (even Photoshop) from a webpage using Javascript.

The same method can be applied to detect the existence of certain software on client's machine like does he have Microsoft Word Viewer installed before he downloads that .doc files from your website. Or what's the version of Microsoft Office or Quicktime installed on his computer ?

The ActiveXObject() constructor function creates an instance of an OLE Automation (ActiveX) object. Once an object is created, you refer to it in code using the object variable you defined. If an instance of the ActiveX object is already running, ActiveXObject() may start a new instance when it creates an object of the required type.

The following code segment lets the user open a Word document directly:
var pause = 0;
var wdDialogFileOpen = 80;
var wdApp = new ActiveXObject("Word.Application");
var dialog = wdApp.Dialogs(wdDialogFileOpen);
var button = dialog.Show(pause);
The preceding code segment references the Word.Application object, and its methods are used later. Notice the hierarchical structure, where one method or property is actually an object that has its own methods and properties.

For opening Microsoft Excel or Visio, replace Word.Application with either Excel.Application or Visio.Application. It should even work with Infopath, OneNote, PowerPoint or even MS Publisher.

Tagged in:

1096
like
0
dislike
0
mail
flag

You must LOGIN to add comments