Skip Headers
Oracle® COM Automation Feature Developer's Guide
11g Release 1 (11.1)

Part Number B31223-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

5 Oracle COM Automation Java Demos

This chapter describes how to use the demonstration program designed for Oracle COM Automation Feature for Java.

This chapter contains these topics:

Overview of Oracle COM Automation Feature for Java Demos

Oracle COM Automation Feature for Java includes an example that demonstrates how to use the feature to build solutions. The demo provides base functionality and can serve as a foundation on which to build more customized, complex applications that use COM Automation. This demo is based on the human resources schema available with the sample schema.

The demo exposes a core set of APIs that enable you to do simple operations using Oracle COM Automation Feature. Each COM Automation server, such as Word and Excel, provides more advanced capabilities than what is offered through the demo APIs. To take advantage of these advanced features, you must design and code your own Java classes.

In this release, COM Automation has provided the Microsoft Word Java Demo, which exchanges data between an Oracle Database instance and Microsoft Word.

Microsoft Word Java Demo

The following sections describe how to install the Microsoft Word Java demo and the APIs that it exposes. This demo is provided as an example of the types of solutions that can be built with Oracle Database and Microsoft Word.

The demo creates a Microsoft Word document containing the names of employees in the database.

The Microsoft Word Java demo is installed in the ORACLE_BASE\ORACLE_HOME\com\java\demos directory and provides the following:

Installing the Microsoft Word Java Demo

Microsoft Word must be installed on the local computer before you install this demo.

To install the demo:

  1. Run the loadjava tool from the command line:

    loadjava -force -resolve -user hr/hr ORACLE_BASE\ORACLE_HOME\com\java\demos\TestWORD.class
    
    
  2. Start SQL*Plus.

    C:\> sqlplus /NOLOG
    
    
  3. Connect to the Oracle Database instance as the user who will use the Microsoft Word demo. For example:

    SQL> connect hr/hr
    
    
  4. Run the TestWORD.sql script to create the call specification:

    SQL> @ORACLE_BASE\ORACLE_HOME\com\java\demos\TestWORD.sql
    

    See Also:

    Oracle Database Java Developer's Guide for further information about the loadjava tool and call specifications

Using the Microsoft Word Java Demo

To use the Word demo:

  1. Set SERVEROUTPUT on at the SQL*Plus prompt:

    SQL> SET SERVEROUTPUT ON
    
    
  2. Call TestWORD() at the SQL*Plus prompt:

    SQL> CALL TestWORD();
    
    

    This creates a Microsoft Word document (worddemoj.doc) in the C:\ directory. The document contains data from the EMPLOYEES and JOBS tables. These tables are available in the human resources schema in the sample schema.

  3. Open worddemoj.doc to see its contents.

Creating a Custom Application

The public class TestWORD API as described in "Core Functionality" , provides a wrapper around the Word.Basic COM Automation class as well as some sample code that demonstrates how to use the wrapper. This code was written to be run on the Oracle database server.

To create a custom application that uses this wrapper:

  1. Instantiate an object of this class.

  2. Create the Word.Basic object by calling the CreateWordObject method.

  3. Create a new Microsoft Word document with the FileNew method, or open an existing document with the FileLoad method.

  4. Use the FormatFontSize, InsertText, and InsertNewLine methods to add text and formatting to the document.

  5. Save the document with the FileSaveAs or the FileSave method.

  6. Call the FileClose method when you are finished with the document.

  7. Call the DestroyWordObject method when you are finished with the Word.Basic object.

Core Functionality

The following subsections describe the APIs that the Microsoft Word Java demo exposes. These APIs are primitive and do not expose all the functionalities that Microsoft Word exposes through COM Automation.

TestWORD

This API is the constructor. It does nothing.

Syntax

public TestWORD()

CreateWordObject

Creates the Word.Basic COM object.

Syntax

public void CreateWordObject(java.lang.String servername)

Where Is
servername the server on which to create the COM object. Specify null or the empty string for the local server.

DestroyWordObject

This API destroys the Word.Basic COM object.

Syntax

public void DestroyWordObject()

FileNew

This API creates a new Microsoft WORD document.

Syntax

public void FileNew()

Remarks

This API is a wrapper for the FileNewDefault COM method of the Word.Basic COM object.

FileLoad

This API loads an existing Microsoft WORD document.

Syntax

public void FileLoad(java.lang.String filename)

Where Is
filename the name of the file to load.

Remarks

This API is a wrapper for the FileOpen COM method of the Word.Basic COM object.

FormatFontSize

This API sets the font size.

Syntax

public void FormatFontSize(long fontsize)

Where Is
fontsize the new font size.

Remarks

This API is a wrapper for the FormatFont COM method of the Word.Basic COM object.

InsertText

This API inserts text into the Microsoft Word document.

Syntax

public void InsertText(java.lang.String textstr)

Where Is
textstr the text to insert.

Remarks

This API is a wrapper for the Insert COM method of the Word.Basic COM object.

InsertNewLine

This API inserts a new line into the Microsoft Word document.

Syntax

public void InsertNewLine()

Remarks

This API is a wrapper for the InsertPara COM method of the Word.Basic COM object.

FileSaveAs

This API saves the Microsoft Word document using a specified name.

Syntax

public void FileSaveAs(java.lang.String filename)

Where Is
filename the name of the file.

Remarks

This API is a wrapper for the FileSaveAs COM method of the Word.Basic COM object.

FileSave

This API saves the Microsoft Word document.

Syntax

public void FileSave()

Remarks

This API is a wrapper for the FileSave COM method of the Word.Basic COM object.

FileClose

This API closes the Microsoft Word document, and exits Microsoft Word.

Syntax

public void FileClose()

Remarks

This API is a wrapper for the FileClose and FileExit COM methods of the Word.Basic COM object.