Home » Developer & Programmer » Forms » Excel sheet read from Forms
Excel sheet read from Forms [message #81722] Sat, 15 March 2003 07:25 Go to next message
Victoria
Messages: 152
Registered: July 2002
Senior Member
hI,
am getting the error 'frm-40735 when-button-pressed trigger raised an unhandled exception ora-305500'
when running the following code...
The error is due to the statemnet

worksheets := ole2.GET_OBJ_PROPERTY(workbooks, 'Worksheets');

This is my code...any help?????
--:filename:=get_file_name;
DECLARE

-- Declare handles to OLE objects
application ole2.obj_type;
workbooks ole2.obj_type;
workbook ole2.obj_type;
worksheet ole2.obj_type;
worksheets ole2.obj_type;
cell ole2.obj_type;

-- Declare handles to OLE argument lists
args ole2.list_type;

check_file text_io.file_type;
no_file exception;
PRAGMA EXCEPTION_INIT (no_file, -302000);
cell_value varchar2(2000);

BEGIN

-- Check the file can be found, if not exception no_file will be raised
check_file := TEXT_IO.FOPEN('C:test.xls','R');
TEXT_IO.FCLOSE(check_file);

application:= ole2.create_obj('Excel.Application');
workbooks := ole2.GET_OBJ_PROPERTY(application, 'Workbooks');
worksheets := ole2.GET_OBJ_PROPERTY(workbooks, 'Worksheets');

-- Open the required workbook
args:= ole2.create_arglist;
ole2.add_arg(args, 'C:test.xls');
workbook := ole2.GET_OBJ_PROPERTY (workbooks, 'Open', args);
ole2.destroy_arglist(args);

-- Open worksheet Sheet1 of that Workbook
args:= ole2.create_arglist;
ole2.add_arg(args, 'Sheet1');
worksheet := ole2.GET_OBJ_PROPERTY (worksheets, 'Worksheets', args);
ole2.destroy_arglist(args);

-- Get value of cell A1 of worksheet Sheet1
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);
cell_value :=ole2.get_char_property(cell, 'Value');
message(cell_value);

ole2.invoke(application,'Quit');

-- Release the OLE2 object handles
ole2.release_obj(application);
ole2.release_obj(workbooks);
ole2.release_obj(workbook);
ole2.release_obj(worksheets);
ole2.release_obj(cell);

EXCEPTION
WHEN no_file THEN
MESSAGE('File not found.');
Re: Excel sheet read from Forms [message #81766 is a reply to message #81722] Tue, 18 March 2003 16:07 Go to previous messageGo to next message
magnetic
Messages: 324
Registered: January 2003
Senior Member
forget about the text_io
you should open the excel application:
example code (excel2000)

PROCEDURE to_excel IS
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.list_type;

cursor Vcursor .....etc.

BEGIN
application := ole2.create_obj('Excel.Application');
ole2.set_property(application, 'Visible', 'False');
workbooks := ole2.get_obj_property(application, 'Workbooks');
workbook := ole2.get_obj_property(workbooks, 'Add');
worksheets := ole2.get_obj_property(workbook, 'Worksheets');
worksheet := ole2.get_obj_property(worksheets, 'Add');

row := 1;
col := 1;

for i in Vcursor -- Open Cursor, that returns "value" value
loop
args := ole2.create_arglist;

ole2.add_arg(args, row);
ole2.add_arg(args, col);

cell := ole2.get_obj_property(worksheet, 'Cells', args);

ole2.destroy_arglist(args);

ole2.set_property(cell, 'Value', i.value);

row := row+1;
col := col+1;
end loop; -- Close cursor

args := ole2.create_arglist;
ole2.add_arg(args, 'c:tmpEXAMPLE.XLS');
ole2.invoke(workbook, 'SaveAs', args);
ole2.destroy_arglist(args);
ole2.invoke(application, 'Quit');
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;
Re: Excel sheet read from Forms [message #82015 is a reply to message #81766] Thu, 10 April 2003 07:57 Go to previous message
Victoria
Messages: 152
Registered: July 2002
Senior Member
Hi,
When i read a value from the excel sheet using 'value' property,few fields its returning,only first few digits(rounded of values) since its(cell`s) property has been set as 'custom' rather 'text'.
So how should i go about it??

Moreover do we have any function keys which exactly map menus in excel and how it can be used in OLE2 ???

Thanks in Advance
~V~
Previous Topic: how to go for form builder code 131
Next Topic: Re: How can i display the time consume in my processing
Goto Forum:
  


Current Time: Thu Jun 27 21:55:52 CDT 2024