DECLARE
i_reporttitle VARCHAR2(200) := 'My excel';
COL1 VARCHAR2(2);
COL2 VARCHAR2(8);
COL3 VARCHAR2(8);
COL4 VARCHAR2(15);
COL5 VARCHAR2(50);
COL6 NUMBER(3,1);
COL7 NUMBER(3,1);
COL8 DATE;
COL9 NUMBER(2);
COL10 NUMBER(2);
COL11 NUMBER(2);
COL12 NUMBER(9,2);
COL13 NUMBER(9,2);
COL14 NUMBER(9,2);
COL15 NUMBER(6);
AMT number;
r number := 1;
c number := 1;
i_orientation VARCHAR2(200) := '1';
i number :=2;
BELTNAME VARCHAR2(200);
/* definiton for commonly used variables and constants and exceptions */
ExcelID ole2.obj_type;
ExcelWorkBooksID ole2.obj_type;
ExcelWorkBookID ole2.obj_type;
ExcelWorkSheetsID ole2.obj_type;
ExcelWorkSheetID ole2.obj_type;
ExcelCellID ole2.obj_type;
ExcelFontID ole2.obj_type;
ExcelPageSetupID ole2.obj_type;
ExcelArgs ole2.list_type;
BEGIN
ExcelID := ole2.create_obj('Excel.Application');
ExcelWorkBooksID := ole2.get_obj_property(ExcelID, 'Workbooks');
ExcelWorkBookID := ole2.invoke_obj(ExcelWorkBooksID, 'Add');
ExcelWorkSheetsID := ole2.get_obj_property(ExcelWorkBookID, 'Worksheets');
ExcelWorkSheetID := ole2.invoke_obj(ExcelWorkSheetsID, 'Add');
ExcelPageSetupID := ole2.get_obj_property(ExcelWorkSheetID, 'PageSetup');
ole2.set_property(ExcelPageSetupID, 'Orientation',i_orientation);
ole2.release_obj(ExcelPageSetupID);
-------------DATED ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,1);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' DATE ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- INVOICE NO ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,2);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' INVOICE_NO ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- PRODUCT NAME ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,3);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' PRODUCT NAME ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- HS CODE ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,4);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' HS CODE ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- PACKING ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,5);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' PACKING ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- UOM ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,6);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' UOM ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
------------- QTY ---------
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i-1);
ole2.add_arg(ExcelArgs,7);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', ' QTY ');
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
------------------------------------------
--FOR BELT IN (SELECT CODE,NAME FROM BELT) LOOP
-- MESSAGE('BELT '||BELT.NAME);
go_block('BLK_EXP');
FIRST_RECORD;
loop
--if :beltname=belt.code then
ole2.set_property(ExcelCellId, 'Value', '1');
go_block('BLK_EXP');
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value',:BLK_EXP.DATED);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+1);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.INVNO);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+2);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.PRODUCT_NAME);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+3);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.HSCODE);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+4);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.PACKING);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+5);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.UOM);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+6);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
ole2.set_property(ExcelCellId, 'Value', :BLK_EXP.QTY);
ExcelFontId := ole2.get_obj_property(ExcelCellId, 'Font');
ole2.set_property(ExcelFontId, 'Bold', 'True');
ole2.set_property(ExcelFontId, 'Size', '10');
ole2.release_obj(ExcelFontId);
ole2.release_obj(ExcelCellId);
/*
ExcelArgs := ole2.create_arglist;
ole2.add_arg(ExcelArgs,i);
ole2.add_arg(ExcelArgs,c+9);
ExcelCellId := ole2.get_obj_property(ExcelWorkSheetId,'cells',ExcelArgs);
ole2.destroy_arglist(ExcelArgs);
--ole2.set_property(ExcelCellId, 'Value', :BELTNAME);
*/
exit when :SYSTEM.LAST_RECORD = 'TRUE';
next_record;
i := i+1;
--end if;
--END LOOP;
end loop;
------ AMOUNT TOTAL --------------
------------------------------------------
ole2.set_property(ExcelID, 'Visible','TRUE');
-- ... and release the allocated resources because they are no longer used by forms
ole2.release_obj(ExcelWorkSheetID);
ole2.release_obj(ExcelWorkSheetsID);
ole2.release_obj(ExcelWorkBookID);
ole2.release_obj(ExcelWorkBooksID);
ole2.release_obj(ExcelID);
END;