Page 1 of 1

[Solved] Correct steps to change format setting Writer

PostPosted: Mon Oct 02, 2017 9:39 am
by janfl
Hi all,

In Xray I can see that all setting(TabStops, Pageformat, Margin and font setting) are set in the way I ordered.

But except the changes in the cursor, nothing changes in the document on the screen.
I think a change properties on the wrong place, in the wrong order and they do not work together.

How to make them work?

Here is my code:

Code: Select all   Expand viewCollapse view
*******************Declaratie variabelen************************
*1. Declaration vaiables
PUBLIC loOfcMgr, loDesktop, loCoreReflection,loDocument,loCursor,loText,loPropertyValue,oStyle,oPageStyle,loPgsz
PUBLIC args(1),tbstps(3),tbstp
***************Maakt Office manager loOfcMgr aan. Deze is public.*********************
*2. Create ServiceManager
LoOfcMgr=CREATEOBJECT("Empty")
COMARRAY(loOfcMgr,10)
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager

************************Maakt Desktop aan.********************
*3. Create Desktop
LoDesktop=CREATEOBJECT("Empty")
COMARRAY(loDesktop,10)
Thisformset.Baseform12.Lofuncties1.ooogetdesktop

**********************Document aanmaken en de args daar voor***********************
*4. Create empty text document
loCoreReflection=CREATEOBJECT("Empty")
COMARRAY(loCoreReflection,10)
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
loDocument=CREATEOBJECT("Empty")
COMARRAY(loDocument,10)
loPropertyValue = CREATEOBJECT("Empty")
loCoreReflection.forName( "com.sun.star.beans.PropertyValue").createobject(@loPropertyValue)
args(1)=loPropertyValue
args(1).name="ReadOnly"
args(1).value=.f.
*fnm="file:///"+STRTRAN(thuispad, "\","/")+"/LIBRARY/Default_A5.ott"
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","Standaard", 0, @args)
**************************Einde aanmaken document********************************
*****************Nu de tabstops***********************************
*5. Create tabstops in scom.sun.star.tyle.Paragraph
oStyle=CREATEOBJECT("Empty")
COMARRAY(oStyle,10)
oStyle=loDocument.createInstance("com.sun.star.style.ParagraphStyle")
oStyle.name="Standaard"
oStyle.FollowStyle="Standaard"
oStyle.IsAutoUpdate=.t.
tbstps(1)=Thisform.lofuncties1.ooocreatestruct("com.sun.star.style.TabStop")
tbstps(2)=Thisform.lofuncties1.ooocreatestruct("com.sun.star.style.TabStop")
tbstps(3)=Thisform.lofuncties1.ooocreatestruct("com.sun.star.style.TabStop")
tbstp=tbstps(1)
WITH tbstp
   .Alignment = 0
   .DecimalChar = 44
   .FillChar = 32
   .Position = 500
ENDWITH
tbstps(1)=tbstp
tbstp=tbstps(2)
WITH tbstp
   .Alignment = 0
   .DecimalChar = 44
   .FillChar = 32
   .Position = 6250
ENDWITH
tbstps(2)=tbstp
tbstp=tbstps(3)
WITH tbstp
   .Alignment = 0
   .DecimalChar = 44
   .FillChar = 32
   .Position = 6750
ENDWITH
tbstps(3)=tbstp
oStyle.SetPropertyValue("ParaTabStops",@tbstps) &&Works
*Thisform.lofuncties1.call_xray(oStyle)
**********************Einde tabstops************************
***********************Marges********************
*6 Create margin in com.sun.star.style.PageStyle
oPageStyle=CREATEOBJECT("Empty")
COMARRAY(oPageStyle,10)
oPageStyle=loDocument.createInstance("com.sun.star.style.PageStyle")
oPageStyle.SetPropertyValue("TopMargin",1000)
oPageStyle.SetPropertyValue("BottomMargin",1500)
oPageStyle.SetPropertyValue("RightMargin",2000)
oPageStyle.SetPropertyValue("LeftMargin",1000)
***********************Einde marges**************************
**********************Pagina formaat**************************
*7 Create in com.sun.star.style.Pagestyle the page sizes using com.sun.star.awt.size
loPgsz=CREATEOBJECT("Empty")
COMARRAY(loPgsz,10)
loPgsz=Thisform.lofuncties1.ooocreatestruct("com.sun.star.awt.size")
loPgsz=oPageStyle.Size
loPgsz.Width=14800
loPgsz.Height=21000
oPageStyle.SetPropertyValue("Size",@loPgsz)
oPageStyle.SetPropertyValue("IsLandscape",.f.)
*******************************Eind pagina formaat***************************
*********************En de tekst.************************************
*8 Create Test object
loText=loDocument.getText() && Create text object
COMARRAY(loText,10)
**********************Einde tekst******************************************
************************** Cursor aanmaken***************************************
*9 Create cursor object
loCursor= loText.createTextCursor()
COMARRAY(loCursor,10)
*******************Einde cursor aanmaken*************************
************************************Instellinge cursor******************************
*10 Character setting in cursor
s
loCursor.SetPropertyValue("CharFontFamily",3)
loCursor.SetPropertyValue("CharFontName","Times New Roman")
loCursor.SetPropertyValue("CharHeight",10)
loCursor.SetPropertyValue("CharWeight",100)
***********************************Einde isntellinge cursor******************************
**************************Nu de tekst er in****************************************
*11 Put some text from object loTest in object lo cursor
loText.insertString(loCursor,"Le premier texte en france", .F.)
*************************Einde tekst er in



Kind regards,

Jan Flikweert

Re: Correct steps to change format setting writer

PostPosted: Tue Oct 03, 2017 12:19 pm
by JohnSUN-Pensioner
OK, Jan,
you create style "Standaard".
What about to apply it to paragraph? I mean something like as
Code: Select all   Expand viewCollapse view
enText = loTex.createEnumeration()
loPara = enText.nextElement()
loPara.ParaStyleName = "Standaard"

Re: Correct steps to change format setting writer

PostPosted: Tue Oct 03, 2017 8:23 pm
by janfl
JohnSUN-Pensioner wrote:OK, Jan,
you create style "Standaard".
What about to apply it to paragraph? I mean something like as
Code: Select all   Expand viewCollapse view
enText = loTex.createEnumeration()
loPara = enText.nextElement()
loPara.ParaStyleName = "Standaard"


Hi JohnSUN,

Thanks for your reply.

So, a text element is a paragraph.
I suppose starting a text element gives the first paragraph.
Sow ith loText=loDocument.getText() I hope I have the first paragraph.
Should in this case loText.parastylename give the samen effect?

Or shall I keep it simple and start as you mentioned?

It seems to be important to choose the style at that moment.

I see you come from KIEV Ukraine. Wich is your native language?
Using Google translate I could translate as is to your native language.

Kind regards,

Jan Flikweert

Re: Correct steps to change format setting writer

PostPosted: Tue Oct 03, 2017 9:33 pm
by janfl
The most important question is with the next code I connect to the paragraph style.
Code: Select all   Expand viewCollapse view
[b]oStyle=loDocument.createInstance("com.sun.star.style.ParagraphStyle")[/b]


I can define tabstops in oStyle.

How to get the tabstops from oStyle on te screen in cursor, in text, in the paragraph?

Re: Correct steps to change format setting writer

PostPosted: Tue Oct 03, 2017 9:45 pm
by RoryOF
Full details of manipulation of Writer (and other OO) documents are given in Andrew Pitonyak's
OpenOffice.org Macros Explained

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 6:14 am
by janfl
RoryOF wrote:Full details of manipulation of Writer (and other OO) documents are given in Andrew Pitonyak's
OpenOffice.org Macros Explained


Hi,

Thanks for your reply.

I have all these publications of Pitonyak and many others. Fine stuff.

The problem how to put things together? How to create a servicemanager, desktop, text object, cursor etc. is not the problem. How to set the value of tabstops is for com.sun.star.style.Paragraphstyle not the problem. The problem is in wich order and what should connect these things so they have effect. How to pass a paragraphstyle with tabstops to your text.

Kind regards,

Jan Flikweert

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 6:55 am
by Zizi64
The problem is in wich order and what should connect these things so they have effect. How to pass a paragraphstyle with tabstops to your text.


You must apply the created/adjusted paragraph style to the desired paragraphs (manuaklly or by a macro). Do you want apply it to all of the paragraphs in your document? Or to the current selection only? Or you want replace the style of some specific paragraphs what have an another style?
https://forum.openoffice.org/en/forum/v ... 20&t=53581

How many different paragraph styles are applied in your document?

Are there some direct (manual) formatting parameteres in the paragraph what you want to modify by the style?
https://forum.openoffice.org/en/forum/v ... =7&t=38858


Can you upload your ODF type sample document with the embedded macro code?

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 9:15 am
by JohnSUN-Pensioner
Oh, Jan, it's not so simple.
janfl wrote:So, a text element is a paragraph.
I suppose starting a text element gives the first paragraph.
Sow ith loText=loDocument.getText() I hope I have the first paragraph.
Should in this case loText.parastylename give the samen effect?

One of possible text element is a paragraph. Also text can contain tables, shapes, images, etc.
That's why you cannot assign a style to the entire text - the text does not have a property ParaStyleName, this is only for paragraphs (individual elements of the text)
New "empty" document by default (!) contains a blank paragraph, and nothing more. You are very prudently specify that the following paragraph should be the same Standaard. In other words, if we are in a new document assign styles Standaard to this single paragraph, then the attachment to the text some new paragraphs will automatically make them the same.
janfl wrote:I see you come from KIEV Ukraine. Wich is your native language?
Using Google translate I could translate as is to your native language.
I can freely read and write in Ukrainian and Russian, for English I sometimes use a Google translate
We can not switch to any other language in this discussion - forum rules require communication in English. All participants of the forum - from Germany, Hungary, India, Africa or China - write here in English. Do you have difficulties with re-translating my message into your native language?

Zizi64 wrote:Can you upload your ODF type sample document with the embedded macro code?
No my friend, he cannot - he try write script for Fox Pro, so he haven't ODF with the embedded macro code

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 9:54 am
by Zizi64

Can you upload your ODF type sample document with the embedded macro code?


No my friend, he cannot - he try write script for Fox Pro, so he haven't ODF with the embedded macro code

:shock: Sorry, I misunderstood something...



We can not switch to any other language in this discussion - forum rules require communication in English. All participants of the forum - from Germany, Hungary, India, Africa or China - write here in English.

...and there are Forums for AOO/LO for other locales/languages:
https://forum.openoffice.org/

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 10:17 am
by JohnSUN-Pensioner
janfl mentioned Fox Pro in some other question (Just when I read the sample code, I could not understand which is it of the programming languages. I had to look at his other questions)

Re: Correct steps to change format setting writer

PostPosted: Wed Oct 04, 2017 12:53 pm
by janfl
Hi all,

I work with VFP. The question is not how to write a vfp program, but in wich order add objects and how to connect properties. See the attachment.

Kind regards,

Jan Flikmweert

Re: Correct steps to change format setting writer

PostPosted: Thu Oct 05, 2017 8:34 am
by janfl
Hi all,

The next command in VFP:

Code: Select all   Expand viewCollapse view
oStyle=loDocument.createInstance("com.sun.star.style.ParagraphStyle")
oStyle.SetPropertyValue("ParaTabStops",m.arrayObject.GetArray())


Result in the Propertie Paragraphstyle.Paratabstops to the next araays using Xray:

Code: Select all   Expand viewCollapse view
          Array : T( 0 To 2 ) As variant 

(0)       | Structure : com.sun.star.style.TabStop
(1)       | Structure : com.sun.star.style.TabStop
(2)       | Structure : com.sun.star.style.TabStop

Alignment                 com.sun.star.style.TabAlign                  0  enum: com.sun.star.style.TabAlign.LEFT
DecimalChar               char                                       ","   
FillChar                  char                                       " "   
Position                  long                                      1500   

Alignment                 com.sun.star.style.TabAlign                  0  enum: com.sun.star.style.TabAlign.LEFT
DecimalChar               char                                       ","   
FillChar                  char                                       " "   
Position                  long                                      3250   

Alignment                 com.sun.star.style.TabAlign                  0  enum: com.sun.star.style.TabAlign.LEFT
DecimalChar               char                                       ","   
FillChar                  char                                       " "   
Position                  long                                      4750   


But do not result in these tabs in Writer.

The same prinpciple but now in Writer Marcro:

Code: Select all   Expand viewCollapse view
sub ParaTabStops
DIM loDocument AS object
DIM loText as object
DIM loCursor AS object
DIM oStyle AS object
DIM loPara AS object
DIM loenText aS object
DIM arrayObject

loDocument=ThisComponent
oStyle = loDocument.createInstance( "com.sun.star.style.ParagraphStyle" )
oStyle.setName( "My new style")
dim tbstps(2) as new com.sun.star.style.TabStop
tbstps(0).Position = 1500
tbstps(0).Alignment = 0
tbstps(0).DecimalChar = 44
tbstps(0).FillChar = 32
tbstps(1).Position = 4500
tbstps(1).Alignment = 0
tbstps(1).DecimalChar = 44
tbstps(1).FillChar = 32
tbstps(2).Position = 7500
tbstps(2).Alignment = 0
tbstps(2).DecimalChar = 44
tbstps(2).FillChar = 32
oStyle.setPropertyValue( "ParaTabStops", tbstps() )
xray oStyle.paratabstops
loText=loDocument.getText()
loenText = loText.createEnumeration()
loPara = loenText.nextElement()
loPara.ParaStyleName = "Standaard"
loCursor= loText.createTextCursor()
loenText = loText.createEnumeration()
loPara = loenText.nextElement()
loPara.ParaStyleName = "Standaard"
loText.insertString(loCursor,"First line"+Chr(13), false)
loCursor= loText.createTextCursor()
loText.insertString(loCursor,"Second line ", false)
end sub


Even with the macro the object oStyle shows the correct paratabstops with xray. But no paratabstops in the document. There is also a new style "My new style" but I do not see this style in Writer.

Could this be an bug, or what am i doing wrong?

Knd regards,

Jan Flikweert