Set TabStops in Writer by Macro

Creating a macro - Writing a Script - Using the API

Set TabStops in Writer by Macro

Postby janfl » Fri Oct 06, 2017 9:23 am

Hi all,

With the next macro in Writer I can see in Xray that Style.Paratabstops has three tabstops. But in my docement there are no new tabs.

What am i doing wrong.

I have a reason to do not use the recorded uno:tabstops macro.

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


Kind regards,


Jan Flikweert
Last edited by janfl on Sun Oct 08, 2017 11:21 am, edited 2 times in total.
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in WRiter by Macro

Postby FJCC » Fri Oct 06, 2017 2:30 pm

First you have to insert the new style into the collection of paragraph styles. Also, later in the code you were applying the style Standaard, not the new style. Try this.
Code: Select all   Expand viewCollapse view
    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() )
    '#########
    oStyleFams = ThisComponent.StyleFamilies
    oPStyles = oStyleFams.getByName("ParagraphStyles")
    oPStyles.insertByName("My new style", oStyle)
    '###################
    'xray oStyle.paratabstops
    loText=loDocument.getText()
    loenText = loText.createEnumeration()
    loPara = loenText.nextElement()
    loPara.ParaStyleName =  "My new style" '###########
    loCursor= loText.createTextCursor()
    loenText = loText.createEnumeration()
    loPara = loenText.nextElement()
    loPara.ParaStyleName = "My new style"  '###########
    loText.insertString(loCursor,"First line"+Chr(13), false)
    loCursor= loText.createTextCursor()
    loText.insertString(loCursor,"Second line ", false)
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 6168
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set TabStops in WRiter by Macro

Postby janfl » Fri Oct 06, 2017 9:17 pm

Hi,

Thank you very much. It works.
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: [Solved]Set TabStops in WRiter by Macro

Postby Villeroy » Sat Oct 07, 2017 12:05 pm

It is important to know that built-in styles are localized.

For instance, the root of paragraph styles (index 0) is always
oRootStyle = oTextDoc.StyleFamilies.getByName("ParagraphStyles").getByName("Standard")
The name you see in the GUI is oRootStyle.DisplayName ("Default Style" in English GUI, "Standard" in German GUI, possibly "Standaard" in your GUI).
Did you want to manipulate the root stlye? Use .getByIndex(0) or .getByName("Standard")
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24656
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved]Set TabStops in WRiter by Macro

Postby janfl » Sat Oct 07, 2017 12:30 pm

Hi,

It is not nessacary to change the root style, but can be an option. Good to know.

The only remaining question is that now it works in a Macro.

But translating this macro to Visual FoxPro does change the property ParaTabStops checking with xRay, but the tabstops are not activated in the document.

Does using API/COM need more property settings? I am looking to it, f.e. pagestyle,framestyle, desktop,document?

I can imagine the situation that a external program differs from starting within Writer, but what is the difference?

Kind regards,


Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in WRiter by Macro

Postby janfl » Sun Oct 08, 2017 11:26 am

Hi all,

VFP can not handle this:
Code: Select all   Expand viewCollapse view
args(0).Value = Array(Array(499,com.sun.star.style.TabAlign.LEFT,","," "),Array(1499,com.sun.star.style.TabAlign.LEFT,","," "))


array(array needs to handled like a string.

But UNO/API needs an array:
Code: Select all   Expand viewCollapse view
dispatcher.executeDispatch(document, ".uno:Tabstops", "", 0, args())


How to convert wit executeDispatch the string "array(array" to an array?

Kind regards,

Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in WRiter by Macro

Postby Zizi64 » Sun Oct 08, 2017 1:14 pm

I do not know anything about the Visual FoxPro...

But as I see it, the Visual FoxPro is discontinued since 2007 (ten years!). Maybe the FoxPro can not support the 'Array of Arrays' type variables?

https://en.wikipedia.org/wiki/Visual_FoxPro
Last edited by Zizi64 on Sun Oct 08, 2017 2:33 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6076
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set TabStops in WRiter by Macro

Postby janfl » Sun Oct 08, 2017 2:25 pm

Zizi64 wrote:I do not know anythig about the Visual FoxPro...

But as I see it, the Visual FoxPro is discontinued since 2007 (ten years!). Maybe the FoxPro can not support the 'Array of Arrays' type variables?

https://en.wikipedia.org/wiki/Visual_FoxPro



Zizi64,

The question can be seen as a uno/api question. This, becuase in VFP we state f.e. arg6(0)="Array(array(1500,0,32,44))" as a string. VFP can handle that.

Then we arrive in UNO/API and that needs an array and not a string. How to change that string in UNO/API to a value/array?
How to change args6 in this statement : dispatcher.executeDispatch(document, ".uno:Tabstops", "", 0, args6())

Kind regards,

Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in WRiter by Macro

Postby Villeroy » Sun Oct 08, 2017 2:52 pm

Why does anybody want to do this programmatically? You could simply distribute templates with styles and use them any way you want (programmatically or not) without all that trouble.
And while doing it the hard way, why do you use dispatches? The API provides everything you need: http://www.openoffice.org/api/docs/comm ... raTabStops, http://www.openoffice.org/api/docs/comm ... bStop.html
And while using dispatches, why do you pass an array of arbitrary data where the API requires an array of property values? http://www.openoffice.org/api/docs/comm ... teDispatch

I can only guess that you do not use MRI? Why not?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24656
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Set TabStops in WRiter by Macro

Postby janfl » Sun Oct 08, 2017 3:35 pm

Zizi64 wrote:I do not know anything about the Visual FoxPro...

But as I see it, the Visual FoxPro is discontinued since 2007 (ten years!). Maybe the FoxPro can not support the 'Array of Arrays' type variables?

https://en.wikipedia.org/wiki/Visual_FoxPro


But to give a direct answer on your returnning question:

In VFP you can create an array of an array.

So when you should write in UNO
args(0).name="Tabstops.TabStops"
args(0).value=array(array(1,1,1,1),array(1,1,1,1)))

In VFP it is possible to create:
DIM tbstps(4,2) or 2,4
args(1).name="Tabstops.TabStops"
To args(1).value you can add array tbstps

argsmay be more then one.

The only question for me is

Assigning array(array()) to args(1).value
seems to be not the same as
assigning tbstps to args(1).value.


Kind regards,

Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in WRiter by Macro

Postby janfl » Tue Oct 10, 2017 4:35 pm

Next statement does behave strange in VFP: oPStyles.insertByName("My new style", oStyle). The result is that is resets the paratabstops to the default value, buth the style is temporarely inserted. It seems to me a little strange first define a tabstop and then insert a style. With Xray I can see that before the statement the paratabstops are set as ordered.
FJCC wrote:First you have to insert the new style into the collection of paragraph styles. Also, later in the code you were applying the style Standaard, not the new style. Try this.
Code: Select all   Expand viewCollapse view
    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() )
    '#########
    oStyleFams = ThisComponent.StyleFamilies
    oPStyles = oStyleFams.getByName("ParagraphStyles")
  [b][u][size=150]  oPStyles.insertByName("My new style", oStyle)[/size][/u][/b]
    '###################
    'xray oStyle.paratabstops
    loText=loDocument.getText()
    loenText = loText.createEnumeration()
    loPara = loenText.nextElement()
    loPara.ParaStyleName =  "My new style" '###########
    loCursor= loText.createTextCursor()
    loenText = loText.createEnumeration()
    loPara = loenText.nextElement()
    loPara.ParaStyleName = "My new style"  '###########
    loText.insertString(loCursor,"First line"+Chr(13), false)
    loCursor= loText.createTextCursor()
    loText.insertString(loCursor,"Second line ", false)


ErrorMessage.odt
Print Screen Error message insertbyname
(22.75 KiB) Downloaded 13 times


How to solve this?
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby FJCC » Tue Oct 10, 2017 10:03 pm

My code applies a new style because I thought that was one of your goals. If you just want to change the tab stops on the existing Default style and affect the whole document, try this.
Code: Select all   Expand viewCollapse view
loDocument=ThisComponent
        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
        '#########
        oStyleFams = ThisComponent.StyleFamilies
        oPStyles = oStyleFams.getByName("ParagraphStyles")
        oStyle = oPStyles.getByName("Standard")
        oStyle.setPropertyValue( "ParaTabStops", tbstps() )
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 6168
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set TabStops in Writer by Macro

Postby Villeroy » Tue Oct 10, 2017 11:34 pm

After 15 years I did not know that UNO type char (16 bit) has to be written as decimal. This is contrary to Basic strings and UNO strings which are encoded in UTF-8.
tbstps(1).DecimalChar = ","
tbstps(1).FillChar = "."
does not even raise an error. It seems to do nothing.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24656
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 8:53 am

Villeroy,

We must wait and see, because until now I did not manage to get tabstops working from VFP. There is always the risk that VFP behaves different then other program languages.

But strange enough: Is there anywhere on the world a working example with tabstops with API COM, except unreadable java stuff?
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 5:17 pm

Hi all,

In Visual Fox Pro the next code run's without error message.
The result of xRay shows a correct structure of an array for ParaTabstops of 3 tabstops.
The style can stay "Standard"
The style in the document is Standard,

oPStyle.insterbyname("My new style",oStyle) generates an error.

but

In the document I do not see the correct tabstops.

How to solve this?

Code: Select all   Expand viewCollapse view
*1. Declaration vaiables and setting UDF
*SET UDFPARMS TO VALUE
Public loOfcMgr, loCoreReflection,loDocument,loCursor,loText,loPropertyValue,oStyle,oPageStyle,loPgsz
Public args(1),tbstps(3),tbstp,loPara,loEnText,oPStyles,oStyleFams
***************Maakt Office manager loOfcMgr aan. Deze is public.*********************
*2. Create ServiceManager
loOfcMgr=Createobject("Empty")
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager
Comarray(loOfcMgr,10)
*3. Create Desktop
Thisformset.Baseform12.Lofuncties1.ooogetdesktop
*4. Create empty text document
loCoreReflection=Createobject("Empty")
Comarray(loCoreReflection,10)
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
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=Createobject("Empty")
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","Standard", 0, @args)
Comarray(loDocument,10)
*****************Nu de tabstops***********************************
*5. Create tabstops in scom.sun.star.tyle.Paragraph
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=Createobject("Empty")
oStyle=loDocument.createInstance("com.sun.star.style.ParagraphStyle")
Comarray(oStyle,10)
oStyle.Name="My new style"
oStyle.SetName("My new style")
*oPStyles.InsertByName("Standard",oStyle)
oStyle.SetPropertyValue("ParaTabStops",@tbstps)
Thisform.lofuncties1.call_xray(oStyle)   && Display the correct structure of an array for 3 tabstops.
*Now let's put some text in it
loText=loDocument.getText()
Comarray(loText,10)
loEnText = loText.createEnumeration()
Comarray(loEnText,10)
loPara = loEnText.nextElement()
Comarray(loPara,10)
loPara.ParaStyleName="Standard"
loCursor= loText.createTextCursor()
Comarray(loCursor,10)
loText.insertString(loCursor,"Le derniere texte en france", .F.)
antwoord=MESSAGEBOX("Do you want to quit?",4)
IF antwoord=0
   Thisform.lofuncties1.__oooreleasecachedvars
   Thisform.lofuncties1.sluiten
ELSE
ENDIF

Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby Villeroy » Wed Oct 11, 2017 5:41 pm

But strange enough: Is there anywhere on the world a working example with tabstops with API COM, except unreadable java stuff?

What are you talking about? Where did you find working Java code? Why don't you share it with us? Just because you can not read Java does not mean that anybody else can't read it.

The StarBasic code provided by FJCC works as intended. With small syntax modifications it works as Python code as well.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24656
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Set TabStops in Writer by Macro

Postby Zizi64 » Wed Oct 11, 2017 6:28 pm

Here is FJCC's StarBasic macro applied in a SAMPLE document.
(The passing the TAB values is an example only...)

SetTabs.odt
(11.25 KiB) Downloaded 11 times
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6076
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 7:25 pm

I received the idea: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Overall_Document_Features

I translated this to VFP. See the next code:
Code: Select all   Expand viewCollapse view
*1. Declaration vaiables and setting UDF
Public loOfcMgr, loCoreReflection,loDocument,loCursor,loText,loPropertyValue,oStyle
Public args(1),tbstps(3),tbstp
PUBLIC  xStyleProps,xSupplier,xFamilies,xFamily,xParaCursor,xCursorProps
***************Maakt Office manager loOfcMgr aan. Deze is public.*********************
*2. Create ServiceManager
loOfcMgr=Createobject("Empty")
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager
Comarray(loOfcMgr,10)
*3. Create Desktop
Thisformset.Baseform12.Lofuncties1.ooogetdesktop
*4. Create empty text document
loCoreReflection=Createobject("Empty")
Comarray(loCoreReflection,10)
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
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=Createobject("Empty")
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","Standard", 0, @args)
Comarray(loDocument,10)
*****************Nu de tabstops***********************************
*5. Create tabstops in scom.sun.star.tyle.Paragraph
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=Createobject("Empty")
Comarray(oStyle,10)
*oPStyles.InsertByName("Standard",oStyle)
*Now let's put some text in it
loText=loDocument.getText()
Comarray(loText,10)
loCursor= loText.createTextCursor()
Comarray(loCursor,10)
&&Ga naar het einde van het document
loCursor.gotoEnd(false)
&&Voeg 2 paragraaf breaks
loText.insertControlCharacter(loCursor, 0, false)
loText.insertControlCharacter( loCursor, 0, false)
&&Maak een nieuwe paragraaf stijl
oStyle =loDocument.createInstance("com.sun.star.style.ParagraphStyle")
&& Toegang tot de XPropertySet interface van de nieuwe stijl
*xStyleProps =loOfcMgr.queryInterface(XPropertySet.class, xStyle)
&&Geef de nieuwe stijl een licht bluawe achtergrond
oStyle.setPropertyValue ("ParaBackColor", 13421823)
oStyle.SetPropertyValue("ParaTabStops",@tbstps)
Thisform.lofuncties1.call_xray(oStyle)
&&Toegang tot de StyleFamiliesSupplier van het document
*xSupplier = loOfcMgr.queryInterface(XStyleFamiliesSupplier.class, loDocument)
&&Gebruik de StyleFamilies supplier van het document om de stijl families
xFamilies = LoDocument.getStyleFamilies()
&&Dan toegang tot de ParagraphStyles familie
xFamily = xFamilies.getByName("ParagraphStyles")
&&Voeg nu de nieuwe stijl met een naam in de paragraph stijl familie
xFamily.insertByName ("All-Singing All-Dancing Style", oStyle)
&&Haal nu de XParagraphProperty interface van de cursor van het document
xParaCursor = loCursor
&&Kies nu de eerste paragraaf(Je had er namelijk 2 ingevoegd)
xParaCursor.gotoPreviousParagraph(false)
xParaCursor.gotoPreviousParagraph(true)
&&Nu toegang tot de proeprtyset van de geselecteerde cursor
xCursorProps = loCursor
&&Zet nu de paragraafstijl van de cursor op de nieuw gemaakte stijl
xParacursor.setPropertyValue("ParaStyleName", "All-Singing All-Dancing Style")
&&We gaan weer terug naar het eind
loCursor.gotoEnd(false)
&&Selecteer de laatste paragraaf van het document
xParaCursor.gotoNextParagraph(true)
&&Zet de stijl van to "Standard"( Dat is voor het programma de standaard stijl.)
xCursorProps.setPropertyValue("ParaStyleName", "Standard")
loText.insertString(loCursor,"Le derniere texte en france", .F.)
antwoord=MESSAGEBOX("Do you want to quit?",4)
IF antwoord=0
   Thisform.lofuncties1.__oooreleasecachedvars
   Thisform.lofuncties1.sluiten
ELSE
ENDIF


The result is a indeed a blue backcolor.
But...... the ordred paratabstops are not been set.
In the next line I use Xray to check the structure of an array of tabstops and it show a array of the three tab stops:

    Alignment integer 0
    DecimalChar char ","
    FillChar char " "
    Position long 500
Because the blue color is set and the tabstop not, I think it is a bug.

See the attachment.
Geen titel 1.odt
Example text file
(8.75 KiB) Downloaded 15 times


Kind regards,


Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby Zizi64 » Wed Oct 11, 2017 7:56 pm

You have set the tabstops of the paragraph style named "Standard" by your macro.
You have set the style and the string of the last pragraph in the document.

But - as I seen it in your code - you have not applied any TAB character in the string...


Code: Select all   Expand viewCollapse view
"Le derniere texte en france"

Try to use something similar code (you know the VFP):
Code: Select all   Expand viewCollapse view
"Le derniere " & CHR(9) & "texte " & CHR(9) & "en france"
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6076
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 8:06 pm

Zizi64 wrote:You have set the tabstops of the paragraph style named "Standard" by your macro.
You have set the style and the string of the last pragraph in the document.

But - as I seen it in your code - you have not applied any TAB character in the string...


Code: Select all   Expand viewCollapse view
"Le derniere texte en france"

Try to use something similar code (you know the VFP):
Code: Select all   Expand viewCollapse view
"Le derniere " & CHR(9) & "texte " & CHR(9) & "en france"



Hi,

Above the text screen of you document there is a part where you can see at wich position the tabstops are set. For user defined they are "Bold". There I can see that they are not set. In no way. At the same time the backgroundcolor blue is visbile.

Kind regards,

Jan Flikweert
Last edited by janfl on Thu Oct 12, 2017 9:05 am, edited 1 time in total.
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 8:09 pm

Zizi64 wrote:Here is FJCC's StarBasic macro applied in a SAMPLE document.
(The passing the TAB values is an example only...)

SetTabs.odt


Hi,

That is the problem. As macro all ideas work. When I neede a macro I even could record a macro. But I work just like someone with Java,VB, Python c etc. with Visual Fox Pro(VFP)

The same code translated from macro to VFP does not work.

Kind regards,

Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby Zizi64 » Wed Oct 11, 2017 8:16 pm

Above the text screen of you document there is a part where you can see at wich position the tabstops are set

The fact "the tabstops exist and set in a paragraph style" not even mean automatically that "there are tabulator characters in the text".
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6076
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set TabStops in Writer by Macro

Postby janfl » Wed Oct 11, 2017 9:29 pm

Indeed: I did not insert tabs in the text. I never stated that. The problem is that they can be set in the paragraphstyle with macro and in VFP. In macro theay are activated and by vfp not.
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Set TabStops in Writer by Macro

Postby janfl » Thu Oct 12, 2017 9:27 am

janfl wrote:I received the idea: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Overall_Document_Features

I translated this to VFP and added a statement regarding paratabstops. See the next code:
Code: Select all   Expand viewCollapse view
*1. Declaration vaiables and setting UDF
Public loOfcMgr, loCoreReflection,loDocument,loCursor,loText,loPropertyValue,oStyle
Public args(1),tbstps(3),tbstp
PUBLIC  xStyleProps,xSupplier,xFamilies,xFamily,xParaCursor,xCursorProps
***************Maakt Office manager loOfcMgr aan. Deze is public.*********************
*2. Create ServiceManager
loOfcMgr=Createobject("Empty")
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager
Comarray(loOfcMgr,10)
*3. Create Desktop
Thisformset.Baseform12.Lofuncties1.ooogetdesktop
*4. Create empty text document
loCoreReflection=Createobject("Empty")
Comarray(loCoreReflection,10)
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
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=Createobject("Empty")
loDocument = loDesktop.loadComponentFromURL("private:factory/swriter","Standard", 0, @args)
Comarray(loDocument,10)
*****************Nu de tabstops***********************************
*5. Create tabstops in scom.sun.star.tyle.Paragraph
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=Createobject("Empty")
Comarray(oStyle,10)
*oPStyles.InsertByName("Standard",oStyle)
*Now let's put some text in it
loText=loDocument.getText()
Comarray(loText,10)
loCursor= loText.createTextCursor()
Comarray(loCursor,10)
&&Ga naar het einde van het document
loCursor.gotoEnd(false)
&&Voeg 2 paragraaf breaks
loText.insertControlCharacter(loCursor, 0, false)
loText.insertControlCharacter( loCursor, 0, false)
&&Maak een nieuwe paragraaf stijl
oStyle =loDocument.createInstance("com.sun.star.style.ParagraphStyle")
&& Toegang tot de XPropertySet interface van de nieuwe stijl
*xStyleProps =loOfcMgr.queryInterface(XPropertySet.class, xStyle)
&&Geef de nieuwe stijl een licht bluawe achtergrond
oStyle.setPropertyValue ("ParaBackColor", 13421823)
oStyle.SetPropertyValue("ParaTabStops",@tbstps)
Thisform.lofuncties1.call_xray(oStyle)
&&Toegang tot de StyleFamiliesSupplier van het document
*xSupplier = loOfcMgr.queryInterface(XStyleFamiliesSupplier.class, loDocument)
&&Gebruik de StyleFamilies supplier van het document om de stijl families
xFamilies = LoDocument.getStyleFamilies()
&&Dan toegang tot de ParagraphStyles familie
xFamily = xFamilies.getByName("ParagraphStyles")
&&Voeg nu de nieuwe stijl met een naam in de paragraph stijl familie
xFamily.insertByName ("All-Singing All-Dancing Style", oStyle)
&&Haal nu de XParagraphProperty interface van de cursor van het document
xParaCursor = loCursor
&&Kies nu de eerste paragraaf(Je had er namelijk 2 ingevoegd)
xParaCursor.gotoPreviousParagraph(false)
xParaCursor.gotoPreviousParagraph(true)
&&Nu toegang tot de proeprtyset van de geselecteerde cursor
xCursorProps = loCursor
&&Zet nu de paragraafstijl van de cursor op de nieuw gemaakte stijl
xParacursor.setPropertyValue("ParaStyleName", "All-Singing All-Dancing Style")
&&We gaan weer terug naar het eind
loCursor.gotoEnd(false)
&&Selecteer de laatste paragraaf van het document
xParaCursor.gotoNextParagraph(true)
&&Zet de stijl van to "Standard"( Dat is voor het programma de standaard stijl.)
xCursorProps.setPropertyValue("ParaStyleName", "Standard")
loText.insertString(loCursor,"Le derniere texte en france", .F.)
antwoord=MESSAGEBOX("Do you want to quit?",4)
IF antwoord=0
   Thisform.lofuncties1.__oooreleasecachedvars
   Thisform.lofuncties1.sluiten
ELSE
ENDIF


The result is a indeed a blue backcolor.
But...... the ordred paratabstops are not been set.
In the next line of the previous code I use Xray to check the structure of an array of tabstops and it show a array of the three tab stops. Here f.e. the first tabstop in xRay:

    Alignment integer 0
    DecimalChar char ","
    FillChar char " "
    Position long 500
Because the blue color is set and the tabstop not, I think it is a bug.

See the attachment.
Geen titel 1.odt
(8.75 KiB) Downloaded 11 times

and:
Here I can see if tabstops are active.jpg


Who knows how to translate the next code to Java and add it to the example: https://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Overall_Document_Features to test it?
Code: Select all   Expand viewCollapse view
With tbstp
   .Alignment = 0
   .DecimalChar = 44
   .FillChar = 32
   .Position = 500
Endwith
oStyle.SetPropertyValue("ParaTabStops",@tbstps)

Kind regards,


Jan Flikweert
Open Office 4.1.3 Windows 10
janfl
 
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests