How to select the current row?

828 views Asked by At

How to select current row in calc of Libreoffice? use macro.

The effect I want to achieve is: If the current row is an odd line, Change the current row background color to blue.

If currentAddress.Row mod 2 = 1 Then
    dim document   as object
    dim dispatcher as object
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "ToPoint"
    args1(0).Value = "$A$3:$H$3"

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

    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "BackgroundColor"
    args2(0).Value = 17798

    dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args2())
End If

args1(0).Value = "$A$3:$H$3" ,

"$A$3:$H$3" . How to represent it as a range with variables? Thanks!

2

There are 2 answers

0
pnuts On

The effect I want to achieve is: If the current row is an odd line, Change the current row background color to blue.

Select all, Format > Conditional Formatting > Condition... > Condition 1, Formula is,

ISODD(ROW())  

New Style... > Background, select blue, OK, OK.

Alternative: Autoformat.

0
patel On

Select a cell and run this code

sub main
    Doc=thiscomponent
    Sheet=Doc.currentcontroller.activesheet
    ActiveCell = Doc.CurrentSelection 
    r = ActiveCell.CellAddress.Row
    if r mod 2 = 1 Then
        Sheet.getRows().getByIndex(r).cellBackColor = RGB(173,216,230) 
    end if   
end sub