Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLE2 / WORD / ORACLE FORMS 5

Status
Not open for further replies.

jhoann

Programmer
Apr 18, 2002
81
PH
Does anybody know how to use OLE2 in oracle forms?
Can someone give me a sample codes regarding OLE2....how to use it and other important matters regarding OLE2...
please I need your help?


Thank you so much!

 
I try this codes but it doesn't work... please check...it doesn't display anything in MS WORD...

declare
application OLE2.OBJ_TYPE;
str OLE2.OBJ_TYPE;
args OLE2.List_Type;

begin
application:=OLE2.CREATE_OBJ('Word.application');
OLE2.SET_PROPERTY(application, 'Visible', 'True');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'hello world');

str := OLE2.Get_Char_Property(str, 'text');
OLE2.SET_PROPERTY(application, 'Value', 'Hello Excel!');
end;
 
I have only used OLE2 for Excel. But I applied the same principles to Word, and here's what I came up with. Hope it helps.

DECLARE
hApplication OLE2.OBJ_TYPE;
hWindow OLE2.OBJ_TYPE;
hPane OLE2.OBJ_TYPE;
hView OLE2.OBJ_TYPE;
hDocuments OLE2.OBJ_TYPE;
hDocument OLE2.OBJ_TYPE;
hSelection OLE2.OBJ_TYPE;
hParagraphFormat OLE2.OBJ_TYPE;
hRange OLE2.OBJ_TYPE;
hFields OLE2.OBJ_TYPE;
hFont OLE2.OBJ_TYPE;

args OLE2.LIST_TYPE;
wdAlignParagraphLeft CONSTANT number(3) := 0;
wdAlignParagraphCenter CONSTANT number(3) := 1;
wdAlignParagraphRight CONSTANT number(3) := 2;
wdSeekCurrentPageHeader CONSTANT number(3) := 9;
wdSeekCurrentPageFooter CONSTANT number(3) := 10;
wdSeekMainDocument CONSTANT number(3) := 0;
wdFieldPage CONSTANT number(3) := 33;
wdFieldNumPages CONSTANT number(3) := 26;
wdPageBreak CONSTANT number(3) := 7;
wdStory CONSTANT number(3) := 6;

myTab CONSTANT varchar2(1) := chr(9);
myBlue CONSTANT number(8) := 16711680; --FF0000
myGreen CONSTANT number(8) := 65280; --00FF00
myRed CONSTANT number(8) := 255; --0000FF
myDkGreen CONSTANT number(8) := 32768; --008000
myBlack CONSTANT number(8) := 0; --000000

myText varchar2(2000);
BEGIN
hApplication:=OLE2.CREATE_OBJ('Word.Application');
OLE2.SET_PROPERTY(hApplication, 'Visible', 1);

hDocuments := OLE2.GET_OBJ_PROPERTY(hApplication, 'Documents');
hDocument := OLE2.INVOKE_OBJ(hDocuments, 'Add');

------------------------------------------
-------- Create Header and Footer --------
------------------------------------------
hWindow := OLE2.GET_OBJ_PROPERTY(hApplication, 'ActiveWindow');
hPane := OLE2.GET_OBJ_PROPERTY(hWindow, 'ActivePane' );
hView := OLE2.GET_OBJ_PROPERTY(hPane, 'View' );

---- Header Section ---
OLE2.SET_PROPERTY(hView, 'SeekView', wdSeekCurrentPageHeader);
hSelection := OLE2.GET_OBJ_PROPERTY(hApplication, 'Selection');
hFont := OLE2.GET_OBJ_PROPERTY(hSelection, 'Font');

OLE2.SET_PROPERTY(hFont, 'Name', 'Times New Roman');
OLE2.SET_PROPERTY(hFont, 'Size', 10);
OLE2.SET_PROPERTY(hFont, 'Bold', FALSE);
OLE2.SET_PROPERTY(hFont, 'Color', MyBlue );

hParagraphFormat := OLE2.GET_OBJ_PROPERTY(hSelection, 'ParagraphFormat');
OLE2.SET_PROPERTY(hParagraphFormat, 'Alignment', wdAlignParagraphCenter);
OLE2.RELEASE_OBJ(hParagraphFormat);

args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'This is a');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.INVOKE(hSelection, 'TypeParagraph');

OLE2.SET_PROPERTY(hFont, 'Size', 16);
OLE2.SET_PROPERTY(hFont, 'Bold', TRUE);
OLE2.SET_PROPERTY(hFont, 'Color', MyDkGreen );

args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'Test Header');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);


---- Footer Section ----
OLE2.SET_PROPERTY(hView, 'SeekView', wdSeekCurrentPageFooter);

hParagraphFormat := OLE2.GET_OBJ_PROPERTY(hSelection, 'ParagraphFormat');
OLE2.SET_PROPERTY(hParagraphFormat, 'Alignment', wdAlignParagraphCenter);
OLE2.RELEASE_OBJ(hParagraphFormat);

hFields := OLE2.GET_OBJ_PROPERTY(hSelection, 'Fields');

args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'Page ');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

hRange := OLE2.GET_OBJ_PROPERTY(hSelection, 'Range');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG_OBJ(args, hRange);
OLE2.ADD_ARG(args, wdFieldPage);
OLE2.INVOKE(hFields, 'Add', args );
OLE2.DESTROY_ARGLIST(args);

args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, ' of ');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

hRange := OLE2.GET_OBJ_PROPERTY(hSelection, 'Range');
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG_OBJ(args, hRange);
OLE2.ADD_ARG(args, wdFieldNumPages);
OLE2.INVOKE(hFields, 'Add', args );
OLE2.DESTROY_ARGLIST(args);

OLE2.RELEASE_OBJ(hRange);
OLE2.RELEASE_OBJ(hFields);

OLE2.SET_PROPERTY(hView, 'SeekView', wdSeekMainDocument);
OLE2.RELEASE_OBJ(hView);
OLE2.RELEASE_OBJ(hPane);
OLE2.RELEASE_OBJ(hWindow);

-----------------------------
-------- Insert Text --------
-----------------------------
hFont := OLE2.GET_OBJ_PROPERTY(hSelection, 'Font');
OLE2.SET_PROPERTY(hFont, 'Name', 'Arial');
OLE2.SET_PROPERTY(hFont, 'Size', 12);
OLE2.SET_PROPERTY(hFont, 'Bold', FALSE );
OLE2.SET_PROPERTY(hFont, 'Color', myBlack );

OLE2.INVOKE(hSelection, 'TypeParagraph');
myText := myTab || 'This text is on the ';
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, myText);
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.SET_PROPERTY(hFont, 'Bold', TRUE);
OLE2.SET_PROPERTY(hFont, 'Color', myRed);
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'first ');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.SET_PROPERTY(hFont, 'Bold', FALSE);
OLE2.SET_PROPERTY(hFont, 'Color', myBlack );
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'page.');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, wdPageBreak);
OLE2.INVOKE(hSelection, 'InsertBreak', args);
OLE2.DESTROY_ARGLIST(args);

----page 2
myText := myTab || 'This text is on the ';
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, myText );
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.SET_PROPERTY(hFont, 'Bold', TRUE);
OLE2.SET_PROPERTY(hFont, 'Color', myBlue);
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'second ');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.SET_PROPERTY(hFont, 'Bold', FALSE);
OLE2.SET_PROPERTY(hFont, 'Color', myBlack );
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'page.');
OLE2.INVOKE(hSelection, 'TypeText', args);
OLE2.DESTROY_ARGLIST(args);

---- go to the top of the first page
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, wdStory);
OLE2.INVOKE(hSelection, 'HomeKey', args);
OLE2.DESTROY_ARGLIST(args);

OLE2.RELEASE_OBJ(hFont);
OLE2.RELEASE_OBJ(hSelection);
OLE2.RELEASE_OBJ(hDocument);
OLE2.RELEASE_OBJ(hDocuments);
OLE2.RELEASE_OBJ(hApplication);
END;

 
thanks a lot sfvb , you're very kind.

Now I'm working with looping using OLE... and I'm having a hard time :c
I need to retrieve some data from the database and display it in WORD.
for example products(field name) :
Customer1
-apple
-banana

Customer2
-apple
-banana
-Mango

how can I make this one a loop :

args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'prod');
formfield:=OLE2.INVOKE_OBJ(formfields,'Item',args);
OLE2.DESTROY_ARGLIST(args);
OLE2.SET_PROPERTY(FORMFIELD,'RESULT',products);

please help....
thank you so much
 
Thanks for everybody, for giving up the successfull code.

I am getting problem with this same code when i will run form on the web, i.e. Application Server (through http service)

Please let me know why this code is not working. Is there any way to Spell Check on the Forms running on web...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top