Quantcast
Channel: Apache OpenOffice Community Forum
Viewing all articles
Browse latest Browse all 1281

Macros and UNO API • SOLVED: Basic macro colors cells incorrectly

$
0
0
This works:

Code:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''sub HighlightOutstandingChecks (jRow as Integer)' Perform outstanding check formatting processing.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''    dim ChkCell           as Object    dim ClrCell           as Object        dim RowCells(0)       as new com.sun.star.beans.PropertyValue    dim CellColor(4)      as new com.sun.star.beans.PropertyValue    dim chkType           as Integer    dim chkString         as String    dim clrVal            as String        dim isCheck           as Boolean    dim isClear           as Boolean        isCheck = False    isClear = False    ' Does this row document a check?    ChkCell  = createUnoService("com.sun.star.table.XCell")            ChkCell  = ThisComponent.CurrentController.ActiveSheet.getCellByPosition(checkColNo, jRow)        ' Look at the check number column contents.    chkType = ChkCell.getType    chkString = Trim(ChkCell.String)    ' If the cell is empty or blank, this is not a check row.    if  CInt(ChkCell.String) = 0 then        isCheck = False    else        isCheck = True    end if       if  isCheck then                 ' Has the check cleared?        ClrCell  = createUnoService("com.sun.star.table.XCell")        ClrCell  = ThisComponent.CurrentController.ActiveSheet.getCellByPosition(clrColNo, jRow)                if  CStr(ClrCell.String) = "x" then            IsClear = True        else            IsClear = False        end if                end if            ' Identify the cells to be formatted.    RowCells(0).Name = "ToPoint"    RowCells(0).Value = "$A$" & CStr(jRow + 1) & ":" & "$Z$" & CStr(jRow + 1)   ' Row/Column NAMES are 1-based.    dispatcher.executeDispatch(Doc, ".uno:GoToCell", "", 0, RowCells())             ' Specify the formatting change.    CellColor(0).Name = "BackgroundPattern.Transparent"    CellColor(0).Value = false    CellColor(1).Name = "BackgroundPattern.BackColor"    CellColor(2).Name = "BackgroundPattern.URL"    CellColor(2).Value = ""    CellColor(3).Name = "BackgroundPattern.Filtername"    CellColor(3).Value = ""    CellColor(4).Name = "BackgroundPattern.Position"    CellColor(4).Value = com.sun.star.style.GraphicLocation.NONE        ' Highlight checks that have not cleared.    ' Can find RGB/color values under Tools > Options > Colors.    ' Cyan 10: 204:255:255 (16777164)    ' Pale Yellow: 255:255:204 (13434879)    ' Numeric color value = red + green×256 + blue×65536        ' NOTE: Due to an OO bug, if Compatability Mode is enabled, when using the RGB function,    '       the Red and Blue components of a color are switched.        if  isCheck then        if  isClear then            ' Set cell background to default color.            ' CellColor(1).Value = RGB(204, 255, 255)              CellColor(1).Value = RGB(255, 255, 204)                else            ' Check has not cleared - highlight the row.            ' CellColor(1).Value = RGB(255, 255, 204)            CellColor(1).Value = RGB(204, 255, 255)        end if                dispatcher.executeDispatch(Doc, ".uno:BackgroundPattern", "", 0, CellColor())    end if        end sub 'HighlightOutstandingChecks[code]

Statistics: Posted by Fafhrd — Fri Jun 28, 2024 6:30 am



Viewing all articles
Browse latest Browse all 1281

Trending Articles