HOW TO - Performing OLE on the client using WebUtil

Introduction

Many Forms applications utilize OLE to perform tight integration with the Windows desktop. However, when moving your Forms application to the Web, the calls to OLE are now running on the application server and not the client machine.

Typically you need OLE to access the machine at which the user is sitting and integrate with the OLE services on the client. For example, loading data into an Excel worksheet and display for the user.

WebUtil provides you the functionality to perform client side OLE integration from within the Forms Java applet.

Set up

For the steps to set up WebUtil, please refer to the WebUtil Familiarization Manual available as part of the software download.

Changing code

Consider the following code:

DECLARE
 app OLE2.OBJ_TYPE;
 docs OLE2.OBJ_TYPE; 
 doc OLE2.OBJ_TYPE; 
 selection OLE2.OBJ_TYPE; 
 args OLE2.LIST_TYPE;
BEGIN
-- create a new document
 app := OLE2.CREATE_OBJ('Word.Application');
 OLE2.SET_PROPERTY(app,'Visible',1);

 docs := OLE2.GET_OBJ_PROPERTY(app, 'Documents');
 doc := OLE2.INVOKE_OBJ(docs, 'add');

 selection := OLE2.GET_OBJ_PROPERTY(app, 'Selection');

 -- insert data into new document from long item
 OLE2.SET_PROPERTY(selection, 'Text', :long_item);

 -- save document as example.doc
 args := OLE2.CREATE_ARGLIST;
 OLE2.ADD_ARG(args, 'c:\temp\example.doc');
 OLE2.INVOKE(doc, 'SaveAs', args);
 OLE2.DESTROY_ARGLIST(args);

 -- close example.doc
 args := OLE2.CREATE_ARGLIST;
 OLE2.ADD_ARG(args, 0);
 OLE2.INVOKE(doc, 'Close', args);
 OLE2.DESTROY_ARGLIST(args);

 OLE2.RELEASE_OBJ(selection);
 OLE2.RELEASE_OBJ(doc); 
 OLE2.RELEASE_OBJ(docs); 

-- exit MSWord 
 OLE2.INVOKE(app,'Quit');
END;

This code opens a Word document to the user and inserts data from a Forms text field into that Word document before saving and closing the file. To perform the same functionality, but on the client side when deployed on the Web, attach the WebUtil object library and PL/SQL library, and replace any instance of OLE2 with CLIENT_OLE2.

The resulting code will now work, as before, but write the file to the client machine.

DECLARE
 app CLIENT_OLE2.OBJ_TYPE;
 docs CLIENT_OLE2.OBJ_TYPE; 
 doc CLIENT_OLE2.OBJ_TYPE; 
 selection CLIENT_OLE2.OBJ_TYPE; 
 args CLIENT_OLE2.LIST_TYPE;
BEGIN
-- create a new document
 app := CLIENT_OLE2.CREATE_OBJ('Word.Application');
 CLIENT_OLE2.SET_PROPERTY(app,'Visible',1);

 docs := CLIENT_OLE2.GET_OBJ_PROPERTY(app, 'Documents');
 doc := CLIENT_OLE2.INVOKE_OBJ(docs, 'add');

 selection := CLIENT_OLE2.GET_OBJ_PROPERTY(app, 'Selection');

 -- insert data into new document from long item
 CLIENT_OLE2.SET_PROPERTY(selection, 'Text', :long_item);

 -- save document as example.doc
 args := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(args, 'c:\temp\example.doc');
 CLIENT_OLE2.INVOKE(doc, 'SaveAs', args);
 CLIENT_OLE2.DESTROY_ARGLIST(args);

 -- close example.doc
 args := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(args, 0);
 CLIENT_OLE2.INVOKE(doc, 'Close', args);
 CLIENT_OLE2.DESTROY_ARGLIST(args);

 CLIENT_OLE2.RELEASE_OBJ(selection);
 CLIENT_OLE2.RELEASE_OBJ(doc); 
 CLIENT_OLE2.RELEASE_OBJ(docs); 

-- exit MSWord 
 CLIENT_OLE2.INVOKE(app,'Quit');
END;