On 11/9/2010 18:58, Michele Zarri wrote:
Hello TJ, Andrew,

Here's the macro I put together this evening.

I tested it and it seems to work but I doubt it is the most efficient
ever written, so I would be very grateful if you could take a look.

At present it applies the background and border to the table where the
cursor is.
I was thinking about applying the change to all the tables in the
document, but it is a risky strategy so at the moment I just check if
the table has more than one row to prevent accidental formatting of the
tips/notes/caution tables.

oh... I forgot... I could not resist stealing the name proposed by TJ :-)

Cheers,

Michele

Sub subBandIt()
Dim oVCurs As Object ' the view cursor
Dim oRows As Object ' the enumerator for the Rows in the table
Dim oRow As Object ' a row object
Dim nRowIndex As Integer
Dim lLightBlue, lWhite As Long
Dim strBorder ' table borders structure
Dim strTemp 'table borders structure

' ==> debugging
' Dim oMRI As Object
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
' <== debugging

lLightBlue = RGB(230, 230, 230)
lWhite = RGB(255, 255, 255)

oVCurs = thisComponent.getCurrentController().getViewCursor()
' check if the view cursor is in a table
if isEmpty(oVCurs.TextTable) Then
MsgBox ("Please place the cursor on a table", 48, "Error!")
Exit Sub
End If

' get the rows collection
oRows = oVCurs.TextTable.getRows()
' get the number of rows in the table
nRows = oRows.getCount()

If nRows = 1 Then
Exit Sub 'table consists of a single row (e.g. notes/tips/caution
End If

'set up the heading background
oRow = oRows.getByIndex(0)
oRow.backcolor = RGB(0, 139, 205)

' ==> debugging
' oMRI = CreateUnoService( "mytools.Mri" )
' oMRI.inspect( oVCurs.TextTable )
' <== debugging

'Do the banding
For nRowIndex = 1 to nRows - 1
oRow = oRows.getByIndex(nRowIndex)
If nRowIndex mod 2 = 0 Then
oRow.backcolor = lLightBlue
Else
oRow.backcolor = lWhite
End If
Next
'Fix the borders
oTable = oVCurs.TextTable

strBorder = oTable.TableBorder
strTemp = strBorder.TopLine : strTemp.Color = RGB(0, 139, 205) :
strTemp.OuterLineWidth = 4 : strBorder.TopLine = strTemp
strTemp = strBorder.LeftLine : strTemp.Color = RGB(0, 139, 205) :
strTemp.OuterLineWidth = 4 : strBorder.LeftLine = strTemp
strTemp = strBorder.RightLine : strTemp.Color = RGB(0, 139, 205) :
strTemp.OuterLineWidth = 4 : strBorder.RightLine = strTemp
strTemp = strBorder.VerticalLine : strTemp.Color = RGB(0, 139, 205) :
strTemp.OuterLineWidth = 2 : strBorder.VerticalLine = strTemp
strTemp = strBorder.HorizontalLine : strTemp.OuterLineWidth = 0 :
strBorder.HorizontalLine = strTemp
strTemp = strBorder.BottomLine : strTemp.Color = RGB(0, 139, 205) :
strTemp.OuterLineWidth = 8 : strBorder.BottomLine = strTemp
oTable.TableBorder = strBorder

End Sub

Michele, it's lovely; well, all but the last part. It would have taken me a week.

subLineUp( strBorder.TopLine, 4 )
'and so forth

Sub subLineUp (oLine as Object, iWide as Integer)

oLine.Color = RGB(0, 139, 205)
oLine.OuterLineWidth = iWide

End Sub 'subLineUp

I haven't tested this yet (I will), but it would only fail if Basic makes a copy to pass in the subroutine call, which I doubt. In that case, a function call, "strBorder.TopLine = fnLineUp( StrBorder.TopLine, 4)" would work, but be messier.
--
/tj/


---------------------------------------------------------------------
To unsubscribe, e-mail: authors-unsubscr...@documentation.openoffice.org
For additional commands, e-mail: authors-h...@documentation.openoffice.org

Reply via email to