Re: 'Save as' operation using winapi in oracle forms

From: Manikandan <member12054_at_dbforums.com>
Date: Sat, 13 Sep 2003 01:57:36 -0400
Message-ID: <3366018.1063432656_at_dbforums.com>


I am attaching the code for saving .xls file as .csv file dynamically...then you can use this file as text file.

PROCEDURE Proc_Format

(

 pvar_fileName in varchar2

)

IS

application ole2.obj_type;

workbooks ole2.obj_type;

workbook ole2.obj_type;

worksheet ole2.obj_type;

args ole2.list_type;

file_han text_io.file_type;

lvar_ColBuf varchar2(800);

lvar_RowBuf varchar2(800);

lvar_insertStmt varchar2(1000);

lvar_successfulFlag char(1):= 'N';

lnum_temp number :=1;

lvar_tempbuf varchar2(400);

lvar_tempbuf1 varchar2(400);

lvar_tempbuf2 varchar2(400);

--lvar_tempbuf3 varchar2(400);

--lvar_tempbuf4 varchar2(400);

lvar_quote char(1):='''';

BEGIN
/*Open the excel file in read mode*/

file_han := text_io.Fopen(pvar_fileName,'r');

text_io.fclose(file_han);

application := ole2.create_obj('Excel.Application');

workbooks := ole2.get_obj_property(application,'Workbooks');

/*open the required work book */

args := ole2.create_arglist;

ole2.add_arg(args,pvar_fileName);

workbook := ole2.invoke_obj(workbooks ,'open',args);

ole2.destroy_arglist(args);

/* open worksheeet sheet1 of that work sheet*/

args := ole2.create_arglist;

ole2.add_arg(args,'sheet1' );

worksheet := ole2.get_obj_property(workbook,'Worksheets',args);

ole2.destroy_arglist(args);

/*save the file as '.csv file'*/

args := ole2.create_arglist;

ole2.add_arg(args,pvar_fileName||'.CSV');

ole2.add_arg(args,6);

oLE2.set_PROPERTY(application,'DisplayAlerts',FALSE);

ole2.invoke(worksheet,'SaveAs',args);

ole2.destroy_arglist(args);

/*Release the ole2 object handles*/

ole2.invoke(application,'Quit');

ole2.release_obj(worksheet);

ole2.release_obj(workbook);

ole2.release_obj(workbooks);

ole2.release_obj(application);

/*Rename the file as .CSV and open it in read mode*/

file_han := Text_IO.Fopen(pvar_filename||'.CSV','r');

Second option is:

To get the number value from the cell in the program you have to get_num_property of OLE2.

To get the character value from the cell in the program you have to get_char_property of OLE2.

Good luck!!!

--
Posted via http://dbforums.com
Received on Sat Sep 13 2003 - 07:57:36 CEST

Original text of this message