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
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