Macro for align table in Writer

Creating a macro - Writing a Script - Using the API

Macro for align table in Writer

Postby Heike » Thu May 11, 2017 6:42 pm

Hello,

at first, sorry for my bad english, I am German, but I try to get help in this forum.

I'd like to creat a macro for a table in writer to make a left align and set a left margin. The macro-recorder can not record the way over the tabledialoge. So I try to write it myself in the macro.

The dispatcher command for left margin have I found, for example:
Code: Select all   Expand viewCollapse view
dim args1(4) as new com.sun.star.beans.PropertyValue
args1(0).Name = "LeftRightMargin.LeftMargin"
args1(0).Value = 1499
args1(2).Name = "LeftRightMargin.RightMargin"
args1(2).Value = 0
args1(3).Name = "LeftRightMargin.LeftRelMargin"
args1(3).Value = 100
args1(4).Name = "LeftRightMargin.RightRelMargin"
args1(4).Value = 100

dispatcher.executeDispatch(document, ".uno:LeftRightMargin", "", 0, args1())


But I search the command for set a align "from left" for the Table .

Look at this picture.

dialog-table-format.JPG


Does anybody have an idea?

Best regards Heike
OpenOffice 4.1 on Windows 8.1
Heike
 
Posts: 2
Joined: Thu May 11, 2017 6:23 pm

Re: macro for align table in writer

Postby Hagar Delest » Fri May 12, 2017 8:09 am

Hi and welcome to the forum!

Here is the code I use to apply a left margin on a table. It should be easy to customize it.

Code: Select all   Expand viewCollapse view
Sub IndentTable
Dim oVC as object      ' Cursor in the document
Dim oTable as object   ' The table where is the cursor
Dim oRow as object      ' The table where is the cursor
Dim nRow as integer
Dim nMarg as integer
' Get the view cursor
oVC = ThisComponent.getCurrentController().getViewCursor()
' Verify that the cursor is in a text table.
If IsNull(oVC.TextTable) OR IsEmpty(oVC.TextTable) Then
   msgbox "No text table is selected"
   Exit Sub
End If
oTable = oVC.TextTable
nMarg = oTable.LeftMargin
oTable.HoriOrient = 0
oTable.LeftMargin = nMarg + 500
oTable.RightMargin = 0
'oTable.HoriOrient = 1
End Sub

See: https://www.openoffice.org/api/docs/com ... ation.html for the alignment options.

Please add [Solved] at the beginning of the title in your first post (top of the topic) with the edit button if your issue has been fixed.
AOO 4.1.4 on Xubuntu 17.10, (Artful Aardvark) and 4.1.3 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 27647
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Macro for align table in Writer

Postby Heike » Fri May 12, 2017 11:46 am

Hello Hagar,

thanks for your welcome and for your help.

I test your code and it works for the left margin, but the last colum form the Table is placed on the right edge. I would like apply the macro on tables with various dimension, so I can't set a fixed right margin. I hope you can understand my plan.

For a better understanding here an image.

tabelle-macro.JPG


best regards Heike
OpenOffice 4.1 on Windows 8.1
Heike
 
Posts: 2
Joined: Thu May 11, 2017 6:23 pm

Re: Macro for align table in Writer

Postby Hagar Delest » Fri May 12, 2017 9:09 pm

If you want to center the table, try:
Code: Select all   Expand viewCollapse view
Sub IndentTable2
Dim oVC as object      ' Cursor in the document
Dim oTable as object   ' The table where is the cursor
Dim oRow as object      ' The table where is the cursor
Dim nRow as integer
Dim nLeft, nRight as integer
' Get the view cursor
oVC = ThisComponent.getCurrentController().getViewCursor()
' Verify that the cursor is in a text table.
If IsNull(oVC.TextTable) OR IsEmpty(oVC.TextTable) Then
   msgbox "No text table is selected"
   Exit Sub
End If
oTable = oVC.TextTable
nLeft = oTable.LeftMargin
nRight = oTable.RightMargin
oTable.LeftMargin = (nLeft + nRight)/2
oTable.RightMargin = (nLeft + nRight)/2
End Sub
AOO 4.1.4 on Xubuntu 17.10, (Artful Aardvark) and 4.1.3 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 27647
Joined: Sun Oct 07, 2007 9:07 pm
Location: France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests