You are on page 1of 2

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;
arglist ole2.list_type;
row_num number;
col_num number;
fontObj ole2.obj_type;
cursor rec is select emp_code,emp_name,to_char(date_of_birth,'dd/mm/rrrr') date_
of_birth from employee_master where date_of_birth is not null;
procedure SetCellValue(rowid number,colid number, cellValue varchar) is
Begin
arglist := ole2.create_arglist;
ole2.add_arg(arglist,rowid);
ole2.add_arg(arglist,colid);
cell := ole2.get_obj_property(worksheet,'Cells',arglist);
fontObj := ole2.get_obj_property(cell,'FOnt');
ole2.destroy_arglist(arglist);
ole2.set_property(cell,'value',cellValue);
ole2.ole2.set_property(fontObj,'Size',16);
ole2.ole2.set_property(fontObj,'BOLD',1);
ole2.ole2.set_property(fontObj,'ColorIndex',7);
ole2.release_obj(cell);
end SetCellValue;
procedure app_init is
Begin
application := ole2.create_obj('Excel.Application');
ole2.set_property(application,'Visible',true);
workbooks := ole2.get_obj_property(application,'workbooks');
workbook := ole2.invoke_obj(workbooks,'add');
worksheets := ole2.get_obj_property(application,'worksheets');
worksheet := ole2.invoke_obj(worksheets,'add');
ole2.set_property(worksheet,'Name','Emp Sheet');
end app_init;
procedure save_excel(path varchar,filename varchar) is
Begin
ole2.release_obj(worksheet);
ole2.release_obj(worksheets);
--Save the Excel file created
if path is not null then
Arglist := ole2.create_arglist;
ole2.add_arg(arglist,path||'\'||filename||'.xls');
ole2.invoke(workbook,'SaveAs',arglist);
ole2.destroy_arglist(arglist);
end if;
end save_excel;
Begin
app_init;
row_num := 1;
col_num := 1;
SetCellValue(row_num,col_num,'Emp Code');
col_num := 2;
SetCellValue(row_num,col_num,'Emp Name');
col_num :=3;
SetCellValue(row_num,col_num,'Date Of Birth');
for i in rec loop
row_num := row_num+1;

col_num := 1;
SetCellValue(row_num,col_num,i.emp_code);
col_num := 2;
SetCellValue(row_num,col_num,i.emp_name);
col_num := 3;
SetCellValue(row_num,col_num,i.date_of_birth);
end loop;
save_excel('d:\excel_export','emp_data');
ole2.release_obj(workbook);
ole2.release_obj(workbooks);
ole2.release_obj(application);
end;

You might also like