OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Width of columns in a Writer table

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
avantman42
Super User
Super User


Joined: 28 Jul 2003
Posts: 751
Location: Staffordshire, UK

PostPosted: Wed Oct 15, 2003 12:23 pm    Post subject: Width of columns in a Writer table Reply with quote

Using the following code, I can create a table in a Writer document which has three columns and one row. So far, so good. However, I need to change the width of the two outer columns, and I can't seem to find out how to do it. Can anyone help?

Code:
Sub rppInsertTable
   
   'Get view cursor
   vCursor = ThisComponent.CurrentController.getViewCursor ()
   'Create a table
   oTable = ThisComponent.createInstance ("com.sun.star.text.TextTable")
   'Initialise table to have one row, three columns
   oTable.initialize (1, 3)
   'Insert table at current cursor position
   ThisComponent.Text.insertTextContent (vCursor, oTable, False)

End Sub


Russ
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Oct 15, 2003 1:41 pm    Post subject: Reply with quote

Here is my best guess so far, but still, not complete success.


Code:


   'Get view cursor
   vCursor = ThisComponent.CurrentController.getViewCursor()
   'Create a table
   oTable = ThisComponent.createInstance ("com.sun.star.text.TextTable")
   'Initialise table to have one row, three columns
   oTable.initialize(1, 3)
   'Insert table at current cursor position
   ThisComponent.Text.insertTextContent (vCursor, oTable, False)
   
   ' Get the property TableColumnSeparators.
   ' This is a property of the TextTable.
   oTblColSeps = oTable.TableColumnSeparators
   ' oTblColSeps is now an array of TableColumSeparator.
   ' Show me the bounds of the array.
   ' Zero to one.  So there are only two separators for
   '  a three column table.
   Print LBound( oTblColSeps ), UBound( oTblColSeps )
   ' Show the two positions:  3333, and 6666
   Print oTblColSeps( 0 ).Position, oTblColSeps( 1 ).Position
   
   ' Change the positions of the two separators.
   oTblColSeps( 0 ).Position = 2000
   oTblColSeps( 1 ).Position = 8000


See these...


http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextTable.html#TableColumnSeparators

http://api.openoffice.org/docs/common/ref/com/sun/star/text/TableColumnSeparator.html
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Oct 15, 2003 7:04 pm    Post subject: Reply with quote

Now that I've gone out to dinner, come home relaxed, and took another look before going to bed, the reason I did not have success earlier is completely obvious. I only needed one final line to make it all work.

Here is a complete working example.

Comment out the Print statements as they were just part of the learning experience. (Remember, I don't know Writer very well.)

Code:

   'Get view cursor
   vCursor = ThisComponent.CurrentController.getViewCursor()
   'Create a table
   oTable = ThisComponent.createInstance ("com.sun.star.text.TextTable")
   'Initialise table to have one row, three columns
   oTable.initialize(1, 3)
   'Insert table at current cursor position
   ThisComponent.Text.insertTextContent (vCursor, oTable, False)
   
   ' Get the property TableColumnSeparators.
   ' This is a property of the TextTable.
   
   oTblColSeps = oTable.TableColumnSeparators
   ' oTblColSeps is now an array of TableColumSeparator.
   
   ' Show me the bounds of the array.
   ' Zero to one.  So there are only two separators for
   '  a three column table.
   Print LBound( oTblColSeps ), UBound( oTblColSeps )
   ' Show the two positions:  3333, and 6666
   Print oTblColSeps( 0 ).Position, oTblColSeps( 1 ).Position
   
   ' Change the positions of the two separators.
   oTblColSeps( 0 ).Position = 2000
   oTblColSeps( 1 ).Position = 8000

   oTable.TableColumnSeparators = oTblColSeps


I just needed a line to assign the modified array back to the table.

There was another property in the two URL's I gave you above that described the Total width of the table. i suspect the two Position properties are relative to this total width property.

Each array element has another property besides the Position property. It has another property to control whether the seperator is visible or not.

Good night.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
avantman42
Super User
Super User


Joined: 28 Jul 2003
Posts: 751
Location: Staffordshire, UK

PostPosted: Thu Oct 16, 2003 1:24 am    Post subject: Reply with quote

Thanks Danny.

I'd found the TableColumnSeperators but couldn't seem to work out how to use them Embarassed
As with so many things, of course, it's easy when you know how Wink

Russ
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Oct 16, 2003 5:24 am    Post subject: Reply with quote

It's like the magician's trick. Once you see how it is done, you feel like "Oh, is that all there is to it?".

This is very much how I felt as I started learning OOo's API.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
poptart992000@yahoo.com
Newbie
Newbie


Joined: 07 Mar 2014
Posts: 2

PostPosted: Mon Mar 10, 2014 2:58 pm    Post subject: VB & oTable.TableColumnSeparators Reply with quote

I realize this is a really old thread, but I have been looking for nearly 2 days on how to change the column widths of a Text Table using Visual Basic 6 but nothing I have done works. So, I came across this and it seems exactly what I need. But... the line
oTblColSeps = oTable.TableColumnSeparators
produces an error Error 438: Object doesn't support this property or method.
But as I write this I realize that this code is for OBasic? maybe and not VB6? (no 'sets') or has OO changed so much that even this VB6 code does not work anymore.

Is there some magic to access these properties using VB6? I notice seemingly random function calls in the various examples I have found and can not understand how they figured to call those routines.
I found code similar to
Code:
    Dim oRow As Object
    Set oRows = oTextTable.getRows()
    Debug.Print oRows.getCount()
    Call oRows.insertByIndex(1, 1)
    Call oTextTable.setPropertyValue("RepeatHeadline", True)


So it appears that I can call "Methods" but accessing "Properties" seems to elude me. From the oTextTable.setPropertyValue() call I can understand that the oTextTable has inherited that method.

[edit 3/13/2014/]
I have found that after I set a property I can read it, but otherwise I get an error Error 438 (see above). However if I set the property then I can read it.
For example j = oTextTable.getBackColor fails, but if I oTextTable.setBackColor(RGB(123,45,54), then j = oTextTable.getBackColor that works and j = the value of RGB(123,45,54).

Thanks for any help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group