[Solved] Macro to change the size of a TextTable

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

[Solved] Macro to change the size of a TextTable

Post by rudolfo »

Hi,
I try to resize/shrink a column in a Text table in OOo Writer with macro commands. I can insert content into the table cells, can modify the borders (of the cells), but I have no clue how I can change the size of the two columns from the inital 50% and 50% to a smaller first column.

Resizing Columns in Calc is no problem. But that method oSheet.Columns(0).Width = 450 won't work in Writer. The Xray inspection tool shows me that the table in Calc supports far more services than the table in Writer. The following 3 services is all I have for a writer table:
  • com.sun.star.document.LinkTarget
  • com.sun.star.text.TextSortable
  • com.sun.star.text.TextTable
Calc has a pair of com.sun.star.table. and com.sun.star.sheet services. Of course I don't expect the Writer table to have the sheet stuff, but why does it not have the com.sun.star.table. services?
I think those allow me to resize cells and columns.

I tried to set the OptimalWidth for a column in the Writer table

Code: Select all

  oColumns = oTable.getColumns()
  Xray oColumns
  oColumns.getByIndex(0).OptimalWidth = True
but I can only access the complete Columns Collection. I can't pick one column from the collection. At least not with the getByIndex() method.

Any ideas how to deal with this are appreciated. Thanks, rudolfo.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
FJCC
Moderator
Posts: 9550
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to change the size of a XTextTable

Post by FJCC »

I remembered this post. I don't have time to look for a work around - I'll try to do that this weekend.
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.
FJCC
Moderator
Posts: 9550
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to change the size of a XTextTable

Post by FJCC »

I found this method for changing the width of table columns

Code: Select all

oDoc = ThisComponent
oTables = oDoc.TextTables
oTable = oTables.getByIndex(0)
TblColSeps = oTable.TableColumnSeparators
TblColSeps(0).Position = 3000  
oTable.TableColumnSeparators = TblColSeps
If a table has two columns, then the array oTable.TableColumnSeparators has only one element that defines the position and the isVisible property of the separator between the two columns. For a three column table there are two elements, and so on.
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.
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Macro to change the size of a XTextTable

Post by rudolfo »

Thanks FJCC, this works like a charm.
I thought that there must be something like that, because the properties dialog of a table has on one page the option to change the cell width but actually not from a cell's point of view but rather from a page side view, because the columnseparator are organized in an array or list much like the tabstops that can be defined for paragraphs.
I need to inspect further if this method only accepts absolut values (with 1 / hundred of a mm as unit) or if you can also specify relatve or percentage values.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: [Solved] Macro to change the size of a TextTable

Post by rudolfo »

I had a look at the API for TableColumnSeparators and learned that the values are relative to .TableColumnRelativeSum. Though on first sight a typical value of 3000 or 1500 makes me think of the hundredth part of a millimeter units, that are used for many other size values.
The .TableColumnRelativeSum property has a value of 10000 in my case (table occupies the full textwidth). If I increase the right margin the value of 10000 doesn't change, but the 3000 for the first column width will have a smaller value in absolute measurement size (like millimeter or point).

After all this makes it a bit difficult to make the first column the size of the image that is contained in it plus a small padding. At the moment I need to figure this out with a trial and error process. But as long as the textwidth or the template for my page doesn't change the macro will do the right thing more me.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Post Reply