简体   繁体   中英

ActiveCell.Offset for libreoffice

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".

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM