Search code examples
libreoffice-calclibreoffice-basic

How to get the row and column number of a cell using a LibreOffice Basic function


I would like to write a Libreoffice-Basic function that takes into account the row and column of the cell where the function is placed. I suppose my problem would be solved if I could define a function such as:

Function MyRowFun()
    MyRowFun = ?????
End Function

replicating the built-in function ROW(). In other words, once I typed "=MyRowFun()" in any given cell, that cell would display the same as if I had typed "=ROW()".

It would also be nice to be able to get the corresponding sheet name.

Thanks very much for any help, such as pointers to online manuals.


PS: After spending a lot of time searching, I have found many places explaining how to identify the cell under the selection, using ThisComponent.CurrentSelection.AbsoluteName, but I care about the cell where the formula is placed, rather than the currently selected cell.


Solution

  • For anyone else who comes across this question, the solution is given in the first comment by @JohnSUN:

    If you know that SHEET(), ROW() and COLUMN() without parameters can return sheet-row-column numbers, then just pass them as parameters when calling your UDF.

    The poster was hoping for a different type of solution but there isn't any other way.