Read From Excel
--------------------------------------------------
DECLARE
application OLE2.OBJ_TYPE;
workbooks OLE2.OBJ_TYPE;
workbook OLE2.OBJ_TYPE;
worksheets OLE2.OBJ_TYPE;
worksheet OLE2.OBJ_TYPE;
cell OLE2.OBJ_TYPE;
args OLE2.OBJ_TYPE;
cell_value number;
BEGIN
application := OLE2.CREATE_OBJ('Excel.Application');
ole2.set_property(application,'Visible','true');
workbooks := OLE2.GET_OBJ_PROPERTY(application, 'Workbooks');
args := OLE2.CREATE_ARGLIST;
ole2.add_arg(args,'c:\test.xls');
workbook := ole2.GET_OBJ_PROPERTY(workbooks,'Open',args);
ole2.destroy_arglist(args);
worksheets := ole2.GET_OBJ_PROPERTY(workbook, 'Worksheets');
worksheet := OLE2.GET_OBJ_PROPERTY(application,'activesheet');
for cols in 1..4 loop -- columns
for rows_index in 1..3 loop -- rows
args:= ole2.create_arglist;
ole2.add_arg(args, rows_index);
ole2.add_arg(args, cols);
cell:= ole2.get_obj_property(worksheet, 'Cells', args);
ole2.destroy_arglist(args);
--cell_value :=ole2.get_char_property(cell, 'Value');
cell_value :=ole2.get_num_property(cell, 'Value');
go_block('t');
create_record;
:t.a := cell_value;
end loop;
end loop;
-- Release the OLE2 object handles
ole2.release_obj(cell);
ole2.release_obj(worksheet);
ole2.release_obj(worksheets);
ole2.release_obj(workbook);
ole2.release_obj(workbooks);
ole2.invoke(application,'Quit');
ole2.release_obj(application);
END;
---------------------------------------------------------------------
notes:
/*
-- PASS VALUE INTO Excel CELL (ROW 371, COL 3)
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 1);
OLE2.ADD_ARG(args, 1);
cell := OLE2.GET_OBJ_PROPERTY(worksheet,'Cells', args);
OLE2.DESTROY_ARGLIST(args);
OLE2.SET_PROPERTY(cell, 'Value', '97FI01');
*/
-- save document as test.xls
/*
OLE2.INVOKE(worksheet, 'Save');
OLE2.INVOKE(workbook, 'Save');
OLE2.INVOKE(workbook,'CLOSE');
*/
Comments