Home » Infrastructure » Windows » OLE2 For word doc
|
Re: OLE2 For word doc [message #232559 is a reply to message #232019] |
Sat, 21 April 2007 03:46 |
srinivas.k2005
Messages: 404 Registered: August 2006
|
Senior Member |
|
|
Hi,
I got the answer .Yes we can insert headers and footers
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;
[MOD-EDIT]Applied code tags. Next time do so yourself!
[Updated on: Mon, 23 April 2007 02:53] by Moderator Report message to a moderator
|
|
|
Re: OLE2 For word doc [message #413937 is a reply to message #232559] |
Sun, 19 July 2009 07:43 |
saeid
Messages: 22 Registered: May 2008
|
Junior Member |
|
|
Hi every body...
I want Open a word file (d:\test1.doc) and change its font.
I can open it but can not change font by this procedure
procedure set_font(p_font_name varchar2,p_font_size number,p_bold boolean) is
/*[selected , font , word are public variables]*/
begin
selected := ole2.get_obj_property(word,'Selection'); --line 1
font := ole2.get_obj_property(selected,'Font'); --line 2
OLE2.SET_PROPERTY(Font, 'Name', p_font_name);
OLE2.SET_PROPERTY(Font, 'Size', p_font_size);
OLE2.SET_PROPERTY(Font, 'Bold', p_bold);
end;
At line2 when i debug form suddenly close "runtime" and exit form.
please assist me...
|
|
|
Goto Forum:
Current Time: Sat Dec 14 16:44:27 CST 2024
|