[Solved] Setting Text Alignment Property

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

[Solved] Setting Text Alignment Property

Post by bartjeman »

I have a Sub to print a text box. I want to pass the desired alignment to the sub - something like this:

Code: Select all

Sub DrawText(RectPosition as Object, Size as Object, oDP as Object, Align as String, TextString as String)
   oShape = ThisComponent.createInstance("com.sun.star.drawing.TextShape")
   oDP.add(oShape)
   oShape.Position = RectPosition
   oShape.Size = Size
   oShape.CharHeight = 12
   Align = "com.sun.star.drawing.TextHorizontalAdjust." & Align
   oShape.TextHorizontalAdjust = Align
   oShape.setString(TextString)
   oShape.CharFontName = "Arial"
End Sub
Of course this does not work so I would appreciate some help on how I can pass CENTER, LEFT or RIGHT to this Sub
Thanks
Last edited by bartjeman on Wed Dec 28, 2016 10:19 pm, edited 1 time in total.
OpenOffice 4.1.7 on Windows 10
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Setting Text Alignment Property

Post by FJCC »

I would use the Align variable in a CASE statement to set another variable to the value of the enum

Code: Select all

SELECT CASE Align
CASE "LEFT"
	Alignment = com.sun.star.drawing.TextHorizontalAdjust.LEFT
CASE "CENTER"
	Alignment = com.sun.star.drawing.TextHorizontalAdjust.CENTER
...
END SELECT
oShape.TextHorizontalAdjust = Alignment
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
bartjeman
Posts: 177
Joined: Sun Jan 03, 2010 6:23 am
Location: Toronto

Re: Setting Text Alignment Property

Post by bartjeman »

Thanks FJCC!
OpenOffice 4.1.7 on Windows 10
Post Reply