How do you find Row index in Calc with Python

I’m trying to populate a list [ rowIndex, prefabFilename ]

How to get the ROW_INDEX?

And how to Modify content of Sheet using that ROW_INDEX?

    gameObjectList = []
    for y in range( 1, 36742 ):
        prefab = active_sheet.getCellByPosition( 8,y )            
        if prefab.String == "":
            break
        gameObjectList.append( [prefab.getCellAddress().ROW_INDEX, prefab.String ])

My solution, not bullet prof, aka required range to start from 0 (and sheet can’t be sorted)

    doc = XSCRIPTCONTEXT.getDocument()
    active_sheet = doc.Sheets['GameObjects']

    gameObjectList = []
    for y in range( 0, 36742 ):
        prefab = active_sheet.getCellByPosition( 8,y )            
        if prefab.String == "":
            break
        address = prefab.getCellAddress()
        gameObjectList.append( [address.Row, prefab.String ])

How I write back to cells

      for q in range( len( gameObjectList )):
          if gameObjectList[q][1].casefold() in prefabFilename.casefold():
              rowIndex = gameObjectList[q][0]
              active_sheet.getCellByPosition( 10, rowIndex ).String = "FOUND"

If you inspect a CellAddress, you see that it consists of 3 numbers Sheet, Column and Row.
https://api.libreoffice.org/docs/idl/ref/structcom_1_1sun_1_1star_1_1table_1_1CellAddress.html

1 Like

now you can refer to the cells directly.
https://wiki.documentfoundation.org/Macros/Python_Guide/Calc/Calc_ranges

When it’s a single cell cell.CellAddress.Row
When it’s a range cell rango.RangeAddress.StartRow

To read and write in a cell

sheet[10,3].String = sheet['A1'].String

By index is [ROW, COLUMN], the start index is 0