Error while using OLE automation in EXCEL

From: Roshan <roshan.bhat_at_in.bosch.com>
Date: 16 Jan 2003 05:57:07 -0800
Message-ID: <362b22ed.0301160557.5071e2ad_at_posting.google.com>



Hello all,

      I am trying to load data from oracle forms(Forms 6.0) into excel sheet using ole. The data gets loaded into excel, and hen i save the excel sheet and then close the excel sheet i get a Program Error which is as follows.
[Quoted] excel.exe has generated errors and will be closed by windows. I have a form with one push button. In the when-button-pressed, the folowing code is executed.
I have excel 97 on windows 2000 machine. Any inputs as to why this happens? I have included the code below.

DECLARE

  • Declare handles to OLE objects application OLE2.OBJ_TYPE; workbooks OLE2.OBJ_TYPE; workbook OLE2.OBJ_TYPE; worksheets OLE2.OBJ_TYPE; worksheet OLE2.OBJ_TYPE; cell OLE2.OBJ_TYPE;
  • Declare handles to OLE argument lists args OLE2.LIST_TYPE;
  • Declare a SQL cursor to be used to fetch the records from
  • the database. CURSOR C1 IS select ename, sal from emp;
  • Declare the PL/SQL variables which will hold the data
  • returned from the database. ename varchar2(30); sal number(8,2);

BEGIN

  • Create handle to application object application:=OLE2.CREATE_OBJ('Excel.Application');
  • Create a Workbooks collection and add new Workbook to
  • Workbooks collection workbooks:=ole2.GET_OBJ_PROPERTY(application, 'Workbooks'); args:=ole2.create_arglist; ole2.add_arg(args, 'C:\ole.XLS'); workbook:=ole2.GET_OBJ_PROPERTY(workbooks,'Open',args); ole2.destroy_arglist(args);
    --workbooks:=OLE2.GET_OBJ_PROPERTY(application, 'Workbooks');
    --workbook:=OLE2.INVOKE_OBJ(workbooks,'Add');
  • Create a Worksheets collection and add new Worksheet to
  • Worksheets collection

  worksheets:=OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');   worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Add');

  • Execute query to fetch employee records OPEN C1;
  • Fetch each employee record and pass values of employee name
  • and salary into Excel (employee names in first column of
  • worksheet and salaries in second column).

  FOR ctr IN 1..14 LOOP

  • Fetch one record and populate PL/SQL variables FETCH C1 INTO ename, sal;
  • Create handle to cell in column 1 of appropriate row in
  • worksheet. (The arguments to the Cells method are the row
  • number and column number of the cell). args:=OLE2.CREATE_ARGLIST; OLE2.ADD_ARG(args, ctr); OLE2.ADD_ARG(args, 1); cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args); OLE2.DESTROY_ARGLIST(args);
  • Put value of employee name into this cell OLE2.SET_PROPERTY(cell, 'Value', ename);
  • Create handle to cell in column 2 of appropriate row in
  • worksheet. args:=OLE2.CREATE_ARGLIST; OLE2.ADD_ARG(args, ctr); OLE2.ADD_ARG(args, 2); cell:=OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args); OLE2.DESTROY_ARGLIST(args);
  • Put value of the employee salary into this cell OLE2.SET_PROPERTY(cell, 'Value', sal);

  END LOOP;
  close C1;
OLE2.SET_PROPERTY(application, 'Visible', 1);

  • Release all OLE object handles OLE2.RELEASE_OBJ(cell); OLE2.RELEASE_OBJ(worksheet); OLE2.RELEASE_OBJ(worksheets); OLE2.RELEASE_OBJ(workbook); OLE2.RELEASE_OBJ(workbooks); OLE2.RELEASE_OBJ(application);

END; Received on Thu Jan 16 2003 - 14:57:07 CET

Original text of this message