Search code examples
pygsheets

pygsheet worksheet size without empty values


How to get row/col number of the last (bottom-right) non-empty cell in worksheet?

Worksheet's rows and cols attributes count also empty cells.


Solution

  • There is no direct function to achieve this in pygsheets. But you can figure this out after getting all the values using get_all_values() and by excluding the empty values.

    cells = wks.get_all_values(include_empty_rows=False, include_tailing_empty=False, returnas='cells')
    
    bottom_right = cells[-1][-1]
    
    # get row col as bottom_right.row, bottom_right.row,
    

    NB: please use the staging version of pygsheets to run this