Zebra Striping

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
php_penguin
Posts: 1
Joined: Sat Dec 08, 2007 6:02 am

Zebra Striping

Post by php_penguin »

Hi there

I'm not much of a scripter... well I do PHP and so on, but BASIC is too boring and annoyingly documented!

Anyway, I am wondering if anyone has done a Zebra Striping macro? I'm sure its possible, but the docs are too much of a mess for me to figure it out for myself!

Thanks in advance!
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: Zebra Striping

Post by probe1 »

php_penguin wrote:if anyone has done a Zebra Striping macro?
I can only guess here.... Are you looking for a macro solution to alternate colors in tables?

for Calc:
colorSelection
Sets alternating colours to the cell selection, multiple selection possible

colorRows
Sets alternating colours the used cell range, to actual or all sheets in document, respects header formats

for Writer:
colorTable
Sets colours to text tables
Definition of two background colors which are applied alternatively to the rows of a text table.


Does this help?
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: Zebra Striping

Post by pitonyak »

Looks like Sun is working on some items related to this... I use a macro such as the following:

Code: Select all

REM  *****  BASIC  *****
Option Explicit

Sub Main
  FormatTable()
  'Inspect()
  'ScreenUpdatingOff()
  'SearchTablesDoom3Email()
  'ScreenUpdatingOn()
End Sub


sub ScreenUpdatingOn
   'ThisComponent.UnlockControllers
   ThisComponent.removeActionLock
end sub

public sub ScreenUpdatingOff
   'ThisComponent.addActionLock
   ThisComponent.LockControllers
end sub 

Sub FormatTable(Optional oUseTable)
  Dim oTable
  Dim oCell
  Dim nRow As Long
  Dim nCol As Long
  
  If IsMissing(oUseTable) Then
    oTable = ThisComponent.CurrentController.getViewCursor().TextTable
  Else
    oTable = oUseTable
  End If
  If IsNull(oTable) OR IsEmpty(oTable) Then
    Print "FormatTable: No table specified"
    Exit Sub
  End If

  Dim v
  Dim x
  v = oTable.TableBorder
  x = v.TopLine
  x.OuterLineWidth = 2
  v.TopLine = x
  
  x = v.LeftLine
  x.OuterLineWidth = 2
  v.LeftLine = x
  
  x = v.RightLine
  x.OuterLineWidth = 2
  v.RightLine = x
  
  x = v.TopLine
  x.OuterLineWidth = 2
  v.TopLine = x
  
  x = v.VerticalLine
  x.OuterLineWidth = 2
  v.VerticalLine = x
  
  x = v.HorizontalLine
  x.OuterLineWidth = 0
  v.HorizontalLine = x
  
  x = v.BottomLine
  x.OuterLineWidth = 2
  v.BottomLine = x
  
  'v.Distance = 51

  oTable.TableBorder = v

  For nRow = 0 To oTable.getRows().getCount() - 1
    For nCol = 0 To oTable.getColumns().getCount() - 1
      oCell = oTable.getCellByPosition(nCol, nRow)
      If nRow = 0 Then
        oCell.BackColor = 128
        SetParStyle(oCell.getText(), "OOoTableHeader")
      Else
        SetParStyle(oCell.getText(), "OOoTableText")
        If nRow MOD 2 = 1 Then
          oCell.BackColor = -1
        Else
          REM color is (230, 230, 230)
          oCell.BackColor = 15132390
        End If
      End If
    Next
  Next
'  Inspect(oTable)
'  Inspect(oCell)
End Sub

Sub SetParStyle(oText, sParStyle As String)
  Dim oEnum
  Dim oPar
  oEnum = oText.createEnumeration()
  Do While oEnum.hasMoreElements()
    oPar = oEnum.nextElement()
    If opar.supportsService("com.sun.star.text.Paragraph") Then
      'oPar.ParaConditionalStyleName = sParStyle
      oPar.ParaStyleName = sParStyle
    End If
  Loop
End Sub
If you look at any of my OOo documentation, you can see how it looks in my text tables.
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
Post Reply