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

前端 未结 5 1086
既然无缘
既然无缘 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:08

    This alternative method resolves issues with the accepted answer by accounting for rows that may have skipped values (such as fancy header sections in a document) as well as sampling the first N columns:

    def next_available_row(sheet, cols_to_sample=2):
      # looks for empty row based on values appearing in 1st N columns
      cols = sheet.range(1, 1, sheet.row_count, cols_to_sample)
      return max([cell.row for cell in cols if cell.value]) + 1
    

提交回复
热议问题