Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.24 Sample 23: COM Program to Control Excel (Late Binding)

Sample 23 is a program that uses the COBOL COM client function to operate Excel.

The COBOL COM client function creates a COM object that uses functions which the COM server supports in the same way as a COBOL method.

Excel is an independent application and also functions as a COM server. Therefore, an application that operates Excel can be written with COBOL.

To run this program, the following products are necessary:

"Excel" is used here as a generic name for these products.

For details on the COBOL COM function, refer to Chapter 24 in the "NetCOBOL User’s Guide".

Overview

The sample program performs the operations listed below for Excel from a COBOL application.

The COBOL COM client function supports the early binding and late binding methods to recognize COM server methods and interfaces.

Late binding is used in this sample.

When late binding is used, usable COBOL descriptions are limited and execution performance is slower than early binding, but late binding is freer from the effects of COM server modifications than early binding. When using late binding this program can operate Excel97 and Excel2000, which are different COM servers.

For details of early binding, see Sample 24, "COM Program to Control Excel (Early Binding)."

Available Programs

Available COBOL Functions

Applicable COBOL Statements

The DISPLAY, IF, INVOKE, PERFORM, and SET statements are used.

Building/Rebuilding

The Project Manager's Build function is used to compile and link this program.

Folder C:\NetCOBOL is assumed below as the location where NetCOBOL is installed.

Change the folder name C:\NetCOBOL to the name of the folder where NetCOBOL is installed.

  1. Start the Project Manager.

  2. Open the project file SAMPLE23.PRJ.

  3. Select "Build" on the "Project" menu.

    After the build terminates, check that SAMPLE23.EXE is created.

Executing the Program

  1. Select "Execute" on the "Project" menu.

    Excel is started. The following message is also displayed on the COBOL console and the system waits for input.

  2. Use the full path-name to specify an Excel file for the test.

    The specified Excel file is opened and the sample program controls Excel.

    The following message is displayed on the COBOL console and the system waits for input again.

  3. Input the type of graph to be created.

    The specified graph is plotted. The following message is displayed on the COBOL console and the system waits for input again.

  4. If the graph is to be printed, specify a printer name. If it is not to be printed, press the ENTER key without inputting data.

    Excel is terminated and the program is terminated. The graph is printed before terminating Excel when a printer name is specified.