0

How can I get access to nearby of selected cell in LibreOffice (OpenOffice)?

I can get only selected cell with "ThisComponent.getCurrentSelection".

I just need an alternative for MS Excel VBA function "ActiveCell.Offset".

user31651
  • 3
  • 2

1 Answers1

2

It seems pretty simple to me:

Function OffsetCell(col_offset, row_offset)
    oSel = ThisComponent.getCurrentSelection()
    oCellAddress = oSel.getCellByPosition(0, 0).getCellAddress()
    oSheet = ThisComponent.CurrentController.ActiveSheet()
    OffsetCell = oSheet.getCellByPosition( _
        oCellAddress.Column + col_offset, _
        oCellAddress.Row + row_offset)
End Function

For example, the function could be used like this:

Sub DisplayOffsetCell()
    offset_cell = OffsetCell(2, 1)
    MsgBox(offset_cell.getString())
End Sub

For reasons I do not understand, there has been quite a bit of discussion about this topic, and several complex solutions have been proposed:

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • For me it seems that instead of: "oCellAddress = oSel.getCellByPosition(0, 0).getCellAddress()", it's only needed: "oCellAddress = oSel.getCellAddress()" – Lv2eof Jul 24 '22 at 00:49