[Solved] Writer change position TableColumnSeparators

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
janfl
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

[Solved] Writer change position TableColumnSeparators

Post by janfl »

Hi all,

My question conserns changing the position of TablecolumnSeparators in Writer.

This job can be done by a macro in OpenOffice, but for my conviniaence it should be nice if it can be done from VFP.

I work with Visual Fox Pro.

The command COMARRAY is used for objects wich communicate with openoffice to tell that VFP works with '1' based arrays.
The @ sign tells oo that this is a array.

The next to command does not have effect. How to use this?

Code: Select all

lorow.setpropertyvalue("TableColumnSeparators",@seps)
loTable.setpropertyvalue("TableColumnSeparators",@seps)
I checkced in the debugger the variable array seps. This contains the correct positions of the separators.

Using Xray learns that The structure TablecolumnSeparators is not changed.

Here by the complete code:

Code: Select all

*Declaratie variabelen
PUBLIC loOfcMgr, loDesktop, loCoreReflection,loDocument,loTextEnum,loCursEnum,loCursor,loText,loArrayWrapper
PUBLIC loDispatcher,args(2),loPropertyValue
PUBLIC loTable,loTextTable,loTextTables,sep,seps(1),lorow,lorows
PUBLIC nDlnmrs,tableWidthIn,laatste_twee_kolommen,eerste_kolom,rst,per_kolom,numseps
*Maakt Office manager loOfcMgr aan. Deze is public.
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager
COMARRAY(loOfcMgr,10)
*Maakt Desktop aan.
Thisformset.Baseform12.Lofuncties1.ooogetdesktop
COMARRAY(loDesktop,10)
*Document aanmaken en de args daar voor
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
COMARRAY(loCoreReflection,10)
loPropertyValue = CREATEOBJECT("Empty")
loCoreReflection.forName( "com.sun.star.beans.PropertyValue").createobject(@loPropertyValue)
args(1)=loPropertyValue
args(1).name="ReadOnly"
args(1).value=.f.
args(2)=loPropertyValue
args(2).name="MacroExecutionMode"
args(2).value=4
*Nu kan het eingenlijke document worden geladen.
fnm="file:///"+STRTRAN(thuispad, "\","/")+"/LIBRARY/Default_A5.ott"
loDocument = loDesktop.loadComponentFromURL(fnm,"_blank", 0, @args)
COMARRAY(loDocument,10)
*En de tekst.
loText=loDocument.getText() && Create text object
COMARRAY(loText,10)
* Cursor aanmaken
loCursor= loText.createTextCursor()
COMARRAY(loCursor,10)
*Dispatcher aanmaken
loDispatcher = loOfcMgr.createInstance ("com.sun.star.frame.DispatchHelper")
**************aanmaak tabel deel 1*********************
loTable = loDocument.createInstance("com.sun.star.text.TextTable")
loTable.initialize(12, 14)
loCursor=loDocument.getText().createTextCursor()
loDocument.GetText().insertTextContent(loCursor, loTable, False)
loTable.GetCellByPosition(1,1).String="Test"
loTable.GetCellByPosition(0,0).BackColor=8421504
******einde aanmaak tabel*****************************
lorow=CREATEOBJECT("Empty")
lorows=CREATEOBJECT("Empty")
TableName="Tabel1"
nDlnmrs=(loTable.Columns.Count()-3)
tableWidthIn = loTable.TableColumnRelativeSum
laatste_twee_kolommen=1600
eerste_kolom=2000
rst=tableWidthIn-eerste_kolom-laatste_twee_kolommen
per_kolom=ROUND(rst/nDlnmrs,0)
LoRows=loTable.GetRows()
LoRow=LoRows.GetByIndex(0)
numseps=ALEN(lorow.TableColumnSeparators)
PUBLIC sep,seps(numseps),s,i,teller
FOR teller=1 TO numseps
seps(teller)=CREATEOBJECT("Empty")
NEXT teller	
FOR teller=1 TO numseps
seps(teller)=Thisform.lofuncties1.ooocreatestruct("com.sun.star.text.TableColumnSeparator")
NEXT teller
FOR i= 1 TO lorows.count
	loRow=LoRows.GetByIndex(i-1)
	seps=loRow.TableColumnseparators
	s=1
	sep=seps(s)
	sep.Position = eerste_kolom
	seps(s)=sep
	for s = 2 to (numseps-2)
		sep=seps(s)
		sep.Position = ROUND((2000+((s-1)*per_kolom)),0)
		Seps(s)=sep
	next s
	s=(numseps-1)
	sep=seps(s)
	sep.Position = ROUND((tableWidthIn-laatste_twee_kolommen),0)
	seps(s)=sep
	s=numseps
	sep=seps(s)
	sep.Position =(tableWidthIn-(laatste_twee_kolommen/2))
	seps(s)=sep
[size=150][b][u]*	loRow.AddPropertyValue("TableColumnSeparators",@seps) &&This does not work. Is a kwon bug
*	loRow.TableColumnseparators=seps &&This does not work because OO sees only they first element of the array
&& and you can not access a single element of "Tablecolumnseparators"
[/u][/b][/size]NEXT i

Last edited by janfl on Wed Oct 11, 2017 10:02 pm, edited 3 times in total.
Open Office 4.1.3 Windows 10
janfl
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Writer change position TableColumnSeparators

Post by janfl »

Hi all,

https://bz.apache.org/ooo/show_bug.cgi?id=55575

I have seen it is noted as a bug.

As pointed out: You can do it by macro(even from template). From VB, java VFP you could run that macro. But SetPropertyvalue from VB,Java and VFP will 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: Writer change position TableColumnSeparators

Post by janfl »

The function SetPropertyValue accepts a array of objects.

Assiging these arrays of objects to ootablecolumnseparators is not accepted. OO sees onley the first element of the array.

Here a example of Tabstops where SetPropertyValue works fine and assiging not. See the lost two lines of the code.

Code: Select all

*******************Declaratie variabelen************************
PUBLIC loOfcMgr, loDesktop, loCoreReflection,loDocument,loCursor,loText,loArrayWrapper
PUBLIC loDispatcher,args(1),loPropertyValue

***************Maakt Office manager loOfcMgr aan. Deze is public.*********************
Thisformset.Baseform12.Lofuncties1.ooogetservicemanager
COMARRAY(loOfcMgr,10)

************************Maakt Desktop aan.********************
Thisformset.Baseform12.Lofuncties1.ooogetdesktop
COMARRAY(loDesktop,10)

**********************Document aanmaken en de args daar voor***********************
loCoreReflection = loOfcMgr.createInstance("com.sun.star.reflection.CoreReflection" )
COMARRAY(loCoreReflection,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(fnm,"_blank", 0, @args)
COMARRAY(loDocument,10)

*Nu de tabstops
PUBLIC tbstps(3),tbstp,oStyle
oStyle=CREATEOBJECT("Empty")
oStyle=loDocument.createInstance("com.sun.star.style.ParagraphStyle")
tbstps(1)=CREATEOBJECT("Empty")
tbstps(2)=CREATEOBJECT("Empty")
tbstps(3)=CREATEOBJECT("Empty")
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)
tbstp.Alignment = 0
tbstp.DecimalChar = 44
tbstp.FillChar = 32
tbstp.Position = 1500
tbstps(1)=tbstp
tbstp=tbstps(2)
tbstp.Alignment = 0
tbstp.DecimalChar = 44
tbstp.FillChar = 32
tbstp.Position = 3250
tbstps(2)=tbstp
tbstp=tbstps(3)
tbstp.Alignment = 0
tbstp.DecimalChar = 44
tbstp.FillChar = 32
tbstp.Position = 4750
tbstps(3)=tbstp
[size=150][b][u]oStyle.SetPropertyValue("ParaTabStops",@tbstps) &&Works
*oStyle.ParatabStops=(tbstps) &&Does not work[/u][/b][/size]
Open Office 4.1.3 Windows 10
janfl
Posts: 29
Joined: Thu Sep 28, 2017 4:17 pm

Re: Writer change position TableColumnSeparators

Post by janfl »

Hi all,

I am looking at the java example concerning column width. I am trying to translate the next statement:

Code: Select all

Object xObj = loTable.getPropertyValue( "TableColumnSeparators" )
TableColumnSeparator[] xSeparators = ( TableColumnSeparator[] )UnoRuntime.queryInterface(    TableColumnSeparator[].class, xObj )
Who knows how to translate the previous code from Java to LibreOffice Macro statement?

So from LO Macro statement I can translate to Visual Fox Pro.

Kind regards,

Jan Flikweert
Open Office 4.1.3 Windows 10
Post Reply