Home » Developer & Programmer » Forms » webutil client_ole2 Microsoft Word - Paragraph Alignment (Forms 11g)
webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661486] Mon, 20 March 2017 11:03 Go to next message
giorkos_s
Messages: 13
Registered: December 2016
Junior Member
Hi All,

I am having issues with Text-Paragraph alignment in Microsoft Word, using webutil client_ole2.
As I have stated in a previous post, I have found code relating to client_ole2 and Microsoft Word. The code goes in great detail about Header, Footer and tables.
All I want is the ability to align Text, change Font- font size, and font color.

I have been able to align text, but in the I Cannot get the "paragraph separation" right.
The code I include is made up of bits of code I have found in searches. The problem with it, is when I use the Paragraph alignment part of the code, which i block-comment out, then the whole document is Aligned to the left.
Obviously I am messing something (or many things up). Can someone shed some light on this and point what I am doing wrong. (I have tried to create a macro in Word, to try and recreate the steps using client_ole2 but I was unable to do so.)

Can you give me any pointer-solution for alignment, and font-size-color please ?

Thanks,

George

P.S The code below aligns testing1 and testing2 to the right and testing3 and testing4 to the left...

DECLARE
v_app CLIENT_OLE2.OBJ_TYPE;
v_docs CLIENT_OLE2.OBJ_TYPE; 
v_doc CLIENT_OLE2.OBJ_TYPE; 
v_selection CLIENT_OLE2.OBJ_TYPE; 
v_arglist CLIENT_OLE2.LIST_TYPE;
V_ParagraphFormat CLIENT_Ole2.Obj_Type;
V_Font CLIENT_Ole2.Obj_Type;
V_Fields CLIENT_Ole2.Obj_Type;
---- WdParagraphAlignment Class members
WdAlignParagraphCenter CONSTANT NUMBER(5) := 1;
WdAlignParagraphLeft CONSTANT NUMBER(5) := 0;
WdAlignParagraphRight CONSTANT NUMBER(5) := 2;


BEGIN
-- create a new document
v_app := CLIENT_OLE2.CREATE_OBJ('Word.Application');
CLIENT_OLE2.SET_PROPERTY(v_app,'Visible',1);

v_docs := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := CLIENT_OLE2.INVOKE_OBJ(v_docs, 'add');

--
--Insert Text
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'testing 1'||chr(13));
client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);
client_ole2.destroy_arglist (v_arglist);
client_ole2.RELEASE_OBJ (v_selection);
--


--
--Insert Text
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'testing 2'||chr(13));
client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);
client_ole2.destroy_arglist (v_arglist);
client_ole2.RELEASE_OBJ (v_selection);
--

--
--Align Paragraph
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
V_ParagraphFormat := CLIENT_Ole2.Get_Obj_Property(V_Selection, 'ParagraphFormat');
CLIENT_Ole2.Set_Property(V_ParagraphFormat, 'Alignment', wdAlignParagraphRIGHT);
CLIENT_Ole2.Release_Obj(V_ParagraphFormat); 
client_ole2.RELEASE_OBJ (v_selection);
--

--
--Insert Text
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'testing 3'||chr(13));
client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);
client_ole2.destroy_arglist (v_arglist);
client_ole2.RELEASE_OBJ (v_selection);
--


--
--Insert Text
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'testing 4'||chr(13));
client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);
client_ole2.destroy_arglist (v_arglist);
client_ole2.RELEASE_OBJ (v_selection);
--

--
--Align Paragraph  ( If i include this part of the code, then the whole document aligns to the left )
/*
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
V_ParagraphFormat := CLIENT_Ole2.Get_Obj_Property(V_Selection, 'ParagraphFormat');
CLIENT_Ole2.Set_Property(V_ParagraphFormat, 'Alignment', wdAlignParagraphLeft);
CLIENT_Ole2.Release_Obj(V_ParagraphFormat); 
client_ole2.RELEASE_OBJ (v_selection);
*/
--


  
 -- save document 
 v_arglist := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(v_arglist, 'c:\temp\example_align.doc');
 CLIENT_OLE2.INVOKE(v_doc, 'SaveAs', v_arglist);
 CLIENT_OLE2.DESTROY_ARGLIST(v_arglist);

 -- close document
 v_Arglist := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(v_arglist, 0);
 CLIENT_OLE2.INVOKE(v_doc, 'Close', v_Arglist);
 CLIENT_OLE2.DESTROY_ARGLIST(v_arglist);

 CLIENT_OLE2.RELEASE_OBJ(v_selection);
 CLIENT_OLE2.RELEASE_OBJ(v_doc); 
 CLIENT_OLE2.RELEASE_OBJ(v_docs); 

-- exit MSWord 
 CLIENT_OLE2.INVOKE(v_app,'Quit');
END;

Re: webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661487 is a reply to message #661486] Mon, 20 March 2017 12:23 Go to previous messageGo to next message
giorkos_s
Messages: 13
Registered: December 2016
Junior Member
Hi All,

I have since my previous post managed to get font , font color and size to display.
I am still puzzled as to the selection and which text exactly gets formated in word. I mean i need to understand what exactly identifies the "selection" ???

the code for the fonts etc.

v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');

V_Font := client_Ole2.Get_Obj_Property(V_Selection, 'Font'); 
client_Ole2.Set_Property(V_Font, 'Name', 'Magneto');
client_Ole2.Set_Property(V_Font, 'Size', 20);
client_ole2.set_property(v_font, 'Color', 16755370);
client_ole2.set_property(v_font, 'Bold', 1);


v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'testing 1'||chr(13));
client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);
client_ole2.destroy_arglist (v_arglist);
Re: webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661489 is a reply to message #661487] Tue, 21 March 2017 04:39 Go to previous messageGo to next message
giorkos_s
Messages: 13
Registered: December 2016
Junior Member
Hi All Again,

I am getting mixed results, when I try to modify the code to get the desired formatting (fonts and alignment) in Word.
I am sure that I am messing the part where the formatting is applied to Word. I do not have a clear understanding of the "Selection" usage from OLE2 and how exactly it applies to Word.
So if you have some general guidelines as to how I select which part gets what formatting, please let me know. Meanwhile, I will continue to try and find a "solution" to my answer, and if I do I will post here .

Thanks all,

George
Re: webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661495 is a reply to message #661489] Tue, 21 March 2017 06:56 Go to previous messageGo to next message
giorkos_s
Messages: 13
Registered: December 2016
Junior Member
Hi All,

I have played a bit more with the code...FINALLY got there...
so if you are looking for a simple piece of code, so that you can align(paragraph) and format (font, size, color) for Microsoft Word , have a look at the following code.
As I said before, this is what i came up with with pieces of code relating to client_ole2 found on the net. Maybe its not the correct way it should be, but it seems to work as expected.

please note that some declared parameters are not used in the sample code, and I provide some comments relating to the mistakes-errors I was doing ...
hope soemone finds it useful !

Thanks,
George

DECLARE
v_app CLIENT_OLE2.OBJ_TYPE;
v_docs CLIENT_OLE2.OBJ_TYPE; 
v_doc CLIENT_OLE2.OBJ_TYPE; 
v_selection CLIENT_OLE2.OBJ_TYPE; 
v_arglist CLIENT_OLE2.LIST_TYPE;
V_ParagraphFormat CLIENT_Ole2.Obj_Type;
V_Font CLIENT_Ole2.Obj_Type;
V_Fields CLIENT_Ole2.Obj_Type;
---- WdParagraphAlignment Class members
WdAlignParagraphCenter CONSTANT NUMBER(5) := 1;
WdAlignParagraphLeft CONSTANT NUMBER(5) := 0;
WdAlignParagraphRight CONSTANT NUMBER(5) := 2;


BEGIN
-- create a new document
v_app := CLIENT_OLE2.CREATE_OBJ('Word.Application');
CLIENT_OLE2.SET_PROPERTY(v_app,'Visible',1);

v_docs := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := CLIENT_OLE2.INVOKE_OBJ(v_docs, 'add');
	
--GET Selection ONLY ONCE !!!!!!!!!
--**********************************																
v_selection := CLIENT_OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');

--***********************************************************************************
--must get object property for v_paragraph format
--for each paragraph you want to set alignment for, EACH TIME for a new paragraph
--and set the alignment
--*********************************************************************************


--Paragraph1
------------------------------------------------------------------------------------------
V_ParagraphFormat := CLIENT_Ole2.Get_Obj_Property(V_Selection, 'ParagraphFormat');
CLIENT_Ole2.Set_Property(V_ParagraphFormat, 'Alignment', wdAlignParagraphCENTER);

--Font Handling
V_Font := client_Ole2.Get_Obj_Property(V_Selection, 'Font');				
client_Ole2.Set_Property(V_Font, 'Name', 'Arial');
client_Ole2.Set_Property(V_Font, 'Size', 30);
client_ole2.set_property(v_font, 'Color', 32768);
client_ole2.set_property(v_font, 'Bold', 1);

--Text
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'I Am Arial in Center'||chr(13));
client_ole2.invoke (v_selection, 'TypeText', v_arglist); -- use TypeText THIS WORKS as expected
--client_ole2.invoke (v_selection, 'InsertAfter', v_arglist); // InsertAfter GIVE WRONG RESULTS - DO NOT USE
client_ole2.destroy_arglist (v_arglist);
------------------------------------------------------------------------------------------     

--Paragraph2
------------------------------------------------------------------------------------------
V_ParagraphFormat := CLIENT_Ole2.Get_Obj_Property(V_Selection, 'ParagraphFormat');
CLIENT_Ole2.Set_Property(V_ParagraphFormat, 'Alignment', wdAlignParagraphRIGHT);

--Font Handling
client_Ole2.Set_Property(V_Font, 'Name', 'Magneto');
client_Ole2.Set_Property(V_Font, 'Size', 25);
client_ole2.set_property(v_font, 'Color', 255);
client_ole2.set_property(v_font, 'Bold', 1);

--Text
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'BIG Magneto Right '||chr(13));
client_ole2.invoke (v_selection, 'TypeText', v_arglist);-- use TypeText THIS WORKS as expected
--client_ole2.invoke (v_selection, 'InsertAfter', v_arglist); //InsertAfter GIVE WRONG RESULTS - DO NOT USE
client_ole2.destroy_arglist (v_arglist);
------------------------------------------------------------------------------------------				
				
				
--Paragraph1
------------------------------------------------------------------------------------------				
V_ParagraphFormat := CLIENT_Ole2.Get_Obj_Property(V_Selection, 'ParagraphFormat');
CLIENT_Ole2.Set_Property(V_ParagraphFormat, 'Alignment', wdAlignParagraphLEFT);

--Font Handling
client_Ole2.Set_Property(V_Font, 'Name', 'Calibri');
client_Ole2.Set_Property(V_Font, 'Size', 12);
client_ole2.set_property(v_font, 'Color', 0);
client_ole2.set_property(v_font, 'Bold', 0);

--Text
v_arglist := client_ole2.create_arglist;
client_ole2.add_arg (v_arglist, 'I am BIG Calibri LEft '||chr(13));
client_ole2.invoke (v_selection, 'TypeText', v_arglist);-- use TypeText THIS WORKS as expected
--client_ole2.invoke (v_selection, 'InsertAfter', v_arglist);//InsertAfter GIVE WRONG RESULTS - DO NOT USE
client_ole2.destroy_arglist (v_arglist);
------------------------------------------------------------------------------------------

			
				
--finally	 release the obects for the following
client_ole2.RELEASE_OBJ (v_paragraphformat);
client_ole2.RELEASE_OBJ (v_selection);

-----------------------------------------------
		

 -- save document as e
 v_arglist := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(v_arglist, 'c:\temp\example_align.doc');
 CLIENT_OLE2.INVOKE(v_doc, 'SaveAs', v_arglist);
 CLIENT_OLE2.DESTROY_ARGLIST(v_arglist);

 -- close
 v_Arglist := CLIENT_OLE2.CREATE_ARGLIST;
 CLIENT_OLE2.ADD_ARG(v_arglist, 0);
 CLIENT_OLE2.INVOKE(v_doc, 'Close', v_Arglist);
 CLIENT_OLE2.DESTROY_ARGLIST(v_arglist);

 CLIENT_OLE2.RELEASE_OBJ(v_selection);
 CLIENT_OLE2.RELEASE_OBJ(v_doc); 
 CLIENT_OLE2.RELEASE_OBJ(v_docs); 

-- exit MSWord 
 CLIENT_OLE2.INVOKE(v_app,'Quit');
END;
Re: webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661497 is a reply to message #661495] Tue, 21 March 2017 10:46 Go to previous messageGo to next message
joy_division
Messages: 4755
Registered: February 2005
Location: East Coast USA
Senior Member
Thank you for this. Very few people follow up with a solution they have figured out on their own.
Re: webutil client_ole2 Microsoft Word - Paragraph Alignment [message #661598 is a reply to message #661497] Fri, 24 March 2017 10:09 Go to previous message
giorkos_s
Messages: 13
Registered: December 2016
Junior Member
joy_division wrote on Tue, 21 March 2017 10:46
Thank you for this. Very few people follow up with a solution they have figured out on their own.

Hi joy_division,

no problem, only seems logical to share it with others who might have the same issue...afterall, i found the various pieces of code i used from other peoples posts !

Thanks All,

George
Previous Topic: Caution's Message With Variable Values
Next Topic: FRM-18222
Goto Forum:
  


Current Time: Sun Jun 25 04:02:42 CDT 2017

Total time taken to generate the page: 0.08527 seconds