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

formatting table borders in OO-Macros

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


Joined: 14 Jul 2008
Posts: 2

PostPosted: Mon Jul 14, 2008 10:58 pm    Post subject: formatting table borders in OO-Macros Reply with quote

Hello,

I'm pretty new to the stuff of programminig macros in OO. Therefore I hope this question does not sound silly to you. I already tried to search in the forum, but I didn't find the right answer(s).

What I want to do is:
Write a macro that inserts a new TextTable into a TextDocument and format it as wanted.

The first thing is quite easy. Here is my code.

Code:
Sub insertPriceTable(pOfferFile)
  iURL = ConvertToURL( pOfferFile )
  iDoc = StarDesktop.loadComponentFromURL( iURL, "_blank", 0, Array(Conversion.MakePropertyValue( "Hidden", True ),))
  ...
  iTable = iDoc.createInstance("com.sun.star.text.TextTable")
  iTable.initialize(1, 6)
  iTable.RepeatHeadline = True
  iDoc.Text.insertTextContent(iCursor, iTable, False)
End Sub


But now I want to format the table, i.e. with no visible borders. Therefore I recorded another macro:

Code:
sub tableborder()
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(4) as new com.sun.star.beans.PropertyValue
args1(0).Name = "BorderInner.Horizontal"
args1(0).Value = Array(0,0,0,0)
args1(1).Name = "BorderInner.Vertical"
args1(1).Value = Array(0,0,0,0)
args1(2).Name = "BorderInner.Flags"
args1(2).Value = 3
args1(3).Name = "BorderInner.ValidFlags"
args1(3).Value = 127
args1(4).Name = "BorderInner.DefaultDistance"
args1(4).Value = 0

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

rem ----------------------------------------------------------------------
dim args2(7) as new com.sun.star.beans.PropertyValue
args2(0).Name = "BorderOuter.LeftBorder"
args2(0).Value = Array(0,0,0,0)
args2(1).Name = "BorderOuter.LeftDistance"
args2(1).Value = 97
args2(2).Name = "BorderOuter.RightBorder"
args2(2).Value = Array(0,0,0,0)
args2(3).Name = "BorderOuter.RightDistance"
args2(3).Value = 97
args2(4).Name = "BorderOuter.TopBorder"
args2(4).Value = Array(0,0,0,0)
args2(5).Name = "BorderOuter.TopDistance"
args2(5).Value = 97
args2(6).Name = "BorderOuter.BottomBorder"
args2(6).Value = Array(0,0,0,0)
args2(7).Name = "BorderOuter.BottomDistance"
args2(7).Value = 97

dispatcher.executeDispatch(document, ".uno:BorderOuter", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(3) as new com.sun.star.beans.PropertyValue
args3(0).Name = "BorderShadow.Location"
args3(0).Value = com.sun.star.table.ShadowLocation.NONE
args3(1).Name = "BorderShadow.Width"
args3(1).Value = 180
args3(2).Name = "BorderShadow.IsTransparent"
args3(2).Value = false
args3(3).Name = "BorderShadow.Color"
args3(3).Value = 8421504

dispatcher.executeDispatch(document, ".uno:BorderShadow", "", 0, args3())


end sub


But how can I use this recorded macro to reuse it in my macro "insertPriceTable" to format the "iTable"? I didn't find anything how to get the XDispatchProvider of the iTable instead of using "document = ThisComponent.CurrentController.Frame" which is not the iTable in fact.

Any help is appreciated.

Thanks in advance.
Back to top
View user's profile Send private message
DVezina
OOo Advocate
OOo Advocate


Joined: 29 Sep 2006
Posts: 248
Location: Orlando

PostPosted: Wed Jul 16, 2008 11:00 am    Post subject: Reply with quote

You need to change the border once you insert the Table object.
This code was borrowed from Andrew Pitonyak's macro documentation which I could not live without.

http://www.pitonyak.org/AndrewMacro.odt
http://www.hentzenwerke.com/catalog/oome.htm


Code:
 

Sub insertPriceTable(pOfferFile)
  iURL = ConvertToURL( pOfferFile )
  iDoc = StarDesktop.loadComponentFromURL( iURL, "_blank", 0, Array(Conversion.MakePropertyValue( "Hidden", True ),))
  ...
  iTable = iDoc.createInstance("com.sun.star.text.TextTable")
  iTable.initialize(1, 6)
  iTable.RepeatHeadline = True
  iDoc.Text.insertTextContent(iCursor, iTable, False)

  Dim x 'represents each BorderLine 
  Dim v 'represents the TableBorder Object as a whole
 
  v = iTable.TableBorder
 
  x = v.TopLine        : x.OuterLineWidth = 0 : v.TopLine = x
  x = v.LeftLine       : x.OuterLineWidth = 0 : v.LeftLine = x
  x = v.RightLine      : x.OuterLineWidth = 0 : v.RightLine = x
  x = v.TopLine        : x.OuterLineWidth = 0 : v.TopLine = x
  x = v.VerticalLine   : x.OuterLineWidth = 0 : v.VerticalLine = x
  x = v.HorizontalLine : x.OuterLineWidth = 0 : v.HorizontalLine = x
  x = v.BottomLine     : x.OuterLineWidth = 0 : v.BottomLine = x

  iTable.TableBorder = v



End Sub
Back to top
View user's profile Send private message
schmidi7
Newbie
Newbie


Joined: 14 Jul 2008
Posts: 2

PostPosted: Wed Jul 16, 2008 11:47 pm    Post subject: Reply with quote

Thank you very much, this was really helpful - espacially the link to Andrew Pitonyak's website!!
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