[Solved] Tabs not being created at the right time

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

[Solved] Tabs not being created at the right time

Post by misitu »

Hello ... me again ... sorry to be a nuisance :oops: (TM)

This bit of code puzzles me. I must have omitted some UNO stuff

What it does is create the custom sized page, insert the text, and then change the tabs.

¡nonono!

what I want it to do is create the custom sized page, change the tabs, and THEN insert the text.

Please can someone point me to the bit of code that needs adding? Thanks.*

Code: Select all

Sub SetPageSize
	oDoc = ThisComponent
	oStyle = oDoc.StyleFamilies.getByName("PageStyles").getByName("Default")
	' units of 1/1000 cm
	oStyle.Width = 21000
	oStyle.Height = 10000
	viewCursor = oDoc.currentController.getViewCursor()
	oCursor = oDoc.Text.createTextCursorByRange(viewCursor.getStart())
	' add tab stop
	Dim tab(0 to 3) as new com.sun.star.style.TabStop
	tab(0).Alignment = com.sun.star.style.TabAlign.RIGHT
	tab(0).DecimalChar = ASC(".")
	tab(0).Position = 5950
	tab(1).Alignment = com.sun.star.style.TabAlign.LEFT
	tab(1).Position = 7010
	tab(2).Alignment = com.sun.star.style.TabAlign.LEFT
	tab(2).Position = 8310
	tab(3).Alignment = com.sun.star.style.TabAlign.RIGHT
	tab(3).DecimalChar = ASC(".")
	tab(3).Position = 16540
	oCursor.ParaTabStops = Array(tab(0), tab(1), tab(2), tab(3))
	insertText("\tthis is an experimental text")
	addParagraph("\tXXXX")
End Sub
Kind regards
David.

* Sorry again! I have to do it this way, otherwise I can't defer the db name to run time. Templates and styles are too high level for this. Thought I should mention.
Last edited by misitu on Mon Nov 14, 2016 10:04 pm, edited 2 times in total.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Tabs not being created at the right time

Post by RoryOF »

As a quick workaround I'd suggest splitting your file manipulation into two parts. Load your tabs, close the file, then reopen the modified file and load your text. This is only a proposed and untested workaround to permit you get on with your project - a proper fix would be better.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Tabs not being created at the right time

Post by misitu »

Thanks. I'll try that. As you say, just to be able to solve all the other bits I don't know as yet. Hopefully, somehow, I'll find in the end which bit of UNO resource I'm failing to invoke :-(
 Edit: mwuhahaah ... :knock:

Figured it!
I had used \t instead of chr(9): in this case chr(9) works perfectly.
A bit of a puzzle, since I use \t \n in another AOOBasic module and that works fine.
 Edit: Yes, on reflection the \t worked in an earlier module because it was passed as a literal to another file (.ics) where the application could interpret it correctly. Meaningless in the context of AOO Basic.
My mistake.. :oops: 
Nothing elaborate this time.

Thanks All
David 
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply