How to find the first empty row of a google spread sheet using python GSPREAD?

前端 未结 5 1079
既然无缘
既然无缘 2020-12-05 11:26

I am struggling to write codes that find me the first empty row of a google sheet.

I am using gspread package from github.com/burnash/gspread

I would be glad

5条回答
  •  粉色の甜心
    2020-12-05 12:25

    If you can count on all of your previous rows being filled in:

    len(sheet.get_all_values()) + 1

    will give you the first free row

    get_all_values returns a 2D list of the sheet's data. Each nested list is a row, so the length of the 2D list is the number of rows that has any data.

    Similar problem is first free column:

    from xlsxwriter.utility import xl_col_to_name
    # Square 2D list, doesn't matter which row len you check
    column_count = len(sheet.get_all_values()[0]) 
    column = xl_col_to_name(column_count)
    

提交回复
热议问题