0% found this document useful (0 votes)
406 views4 pages

Usar Ole2 Abrir Excel Files

This package defines procedures and functions to export data to an Excel spreadsheet using the OLE2 interface. It includes procedures to open and save an Excel application and workbook, add and retrieve data from cells, merge cells, and close the application. Functions allow reading cell values as different data types. The package provides an interface to access Excel objects and manipulate the spreadsheet programmatically.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
406 views4 pages

Usar Ole2 Abrir Excel Files

This package defines procedures and functions to export data to an Excel spreadsheet using the OLE2 interface. It includes procedures to open and save an Excel application and workbook, add and retrieve data from cells, merge cells, and close the application. Functions allow reading cell values as different data types. The package provides an interface to access Excel objects and manipulate the spreadsheet programmatically.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

PACKAGE Export2Excel IS Application ole2.obj_type; WorkBooks ole2.obj_type; Workbook ole2.obj_type; Worksheets ole2.obj_type; Worksheet ole2.obj_type; V_Border ole2.

obj_type; ExcelFont ole2.obj_type; Cell ole2.obj_type; Arg ole2.list_type; ccol ole2.obj_type; rrow ole2.obj_type; Filename Varchar(100); procedure OpenApplication(Filename varchar default 'New' ); Procedure OpenWorksheet(WorksheetName Varchar default 'New' ); procedure WriteIntoCell(rowno number,colno number,Fvalue varchar,typ varchar,b order boolean,font boolean); procedure MergeCells(Rstarting char,Rending char,Cstarting char,Cending char); function ReadFromCell(rowno number,colno number,dtype Char) Return Varchar; Procedure VisibleApps(Val Boolean); Procedure SaveFile(Filename varchar); Procedure ReleaseWorksheet(Filename varchar default 'New'); procedure CloseApplication; END; PACKAGE BODY Export2Excel IS Procedure OpenApplication(Filename varchar default 'New') Is Begin Application := ole2.create_obj('Excel.Application'); Workbooks := ole2.get_obj_property(Application,'Workbooks'); --Open Excisiting Excel File If Filename <> 'New' Then Arg := ole2.create_arglist; ole2.add_arg(Arg,Filename); Workbook := ole2.get_obj_property(Workbooks,'Open',Arg); ole2.destroy_arglist(arg); Else Workbook := ole2.invoke_obj(workbooks,'Add'); End If; End OpenApplication; Procedure OpenWorksheet(Worksheetname varchar default 'New') is Begin --Open Excisiting Excel Sheet If Worksheetname <> 'New' Then Arg := ole2.create_arglist; ole2.add_arg(Arg,Worksheetname); WorkSheet := ole2.get_obj_property(Workbook,'WorkSheets',Arg); ole2.destroy_arglist(arg); Else WorkSheets := ole2.get_obj_property(Workbook,'WorkSheets'); Worksheet := ole2.invoke_obj(Worksheets,'Add'); End If; End OpenWorksheet; Procedure WriteIntoCell(rowno number,colno number,Fvalue varchar,typ varchar,b

order boolean, Font Boolean) Is Begin Arg := ole2.create_arglist; ole2.add_arg(Arg,rowno); ole2.add_arg(Arg,colno); Cell := ole2.get_obj_property(WorkSheet,'Cells',Arg); ole2.destroy_arglist(arg);

If typ = 'CHAR' Then If Substr(Fvalue,1,1) = '0' Then ole2.Set_property(Cell,'Value',''''||Fvalue); Else ole2.Set_property(Cell,'Value',Fvalue); End if; ole2.Set_property(Cell,'NumberFormat','@'); Else If typ = 'NUMBER' Then ole2.Set_property(Cell,'Value',Fvalue); ole2.Set_property(Cell,'NumberFormat','####0.00'); Else ole2.Set_property(Cell,'Value',Fvalue); End if; End if; If substr(Fvalue,3,1) in ('-','/','.') and substr(Fvalue,7,1) in (' -','/','.') Then ole2.Set_property(Cell,'NumberFormat','d-mmm-yyyy'); End If;

If Font Then ExcelFont := ole2.get_obj_property(Cell,'Font'); ole2.Set_property(ExcelFont,'Bold','True'); ole2.Set_property(ExcelFont,'Size',10); ole2.release_obj(ExcelFont); End If; If Border Then V_border := ole2.get_obj_property(Cell,'Borders'); ole2.Set_property(V_border,'LineStyle',1); ole2.release_obj(V_border); End If; arg := ole2.create_arglist; ole2.add_arg(arg,colno); ccol := ole2.get_obj_property(worksheet,'Columns', arg); ole2.destroy_arglist(arg); ole2.invoke(ccol,'Autofit'); ole2.release_obj(cell); End WriteIntoCell; Procedure MergeCells (Rstarting char,Rending char,Cstarting char,Cending char) is temp1 varchar2(20); Begin

arg := ole2.create_arglist; ole2.add_arg(arg,Cstarting||':'||Cending); ccol := ole2.get_obj_property(worksheet,'Columns', arg); ole2.destroy_arglist(arg); arg := ole2.create_arglist; ole2.add_arg(arg,Rstarting||':'||Rending); rrow := ole2.get_obj_property(ccol, 'Rows', arg); ole2.destroy_arglist(arg); ole2.invoke(rrow, 'Merge'); Arg := ole2.create_arglist; ole2.add_arg(Arg,Rstarting); rrow := ole2.get_obj_property(WorkSheet,'Rows',Arg); ole2.destroy_arglist(arg); ole2.set_property(rrow,'RowHeight',30); Arg := ole2.create_arglist; ole2.add_arg(Arg,Rstarting); ole2.add_arg(Arg,Cstarting); Cell := ole2.Get_Obj_Property(Worksheet,'Cells',Arg); ole2.destroy_arglist(arg); ole2.set_property(Cell,'Wraptext','true'); ole2.set_property(Cell,'HorizontalAlignment',-4108); ole2.set_property(Cell,'VerticalAlignment',-4108); End; Function ReadFromCell(rowno number,colno number,dtype char) Return Varchar is Begin Arg := ole2.create_arglist; ole2.add_arg(Arg,rowno); ole2.add_arg(Arg,colno); Cell := ole2.get_obj_property(WorkSheet,'Cells',Arg); If dtype = 'NUMBER' Then Return(ole2.get_num_property(Cell,'Value')); Elsif dtype = 'CHAR' Then Return(ole2.get_char_property(Cell,'Value')); Else Return(ole2.get_char_property(Cell,'Text')); End If; End ReadFromCell; Procedure VisibleApps(Val Boolean) Is Begin ole2.Set_property(Application,'Visible',val); End; Procedure SaveFile(Filename varchar) Is Begin Arg := ole2.create_arglist; ole2.add_arg(Arg,Filename); ole2.set_property(workbook,'Save',Arg); ole2.destroy_arglist(arg); End SaveFile; Procedure ReleaseWorksheet(Filename varchar default 'New') Is Begin

ole2.release_obj(Worksheet); If Filename = 'New' Then ole2.release_obj(WorkSheets); End If; end; Procedure CloseApplication Is Begin ole2.release_obj(Workbook); ole2.release_obj(Workbooks); ole2.invoke(Application,'Quit'); ole2.release_obj(Application); End CloseApplication; END;

You might also like