Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append a new row to the end of sheets using Gspread

Tags:

gspread

I have this code, I need to append the values to the columns in my google sheet and the values should be added at the end of the sheet in a new row without deleting existing datas

all_values = worksheet.get_all_values()
row_count = len(all_values)
sheet_range = "'{}'!{row}:{row}".format(worksheet.title, row=row_count+1+insert_count)

values = {
  "Name": "Ford",
  "Age": "34",
  "Color": 'Blue'
}
worksheet.append_row(sheet_range, values)
like image 302
CodeRed Avatar asked Oct 19 '25 03:10

CodeRed


1 Answers

I figured it out, it's actually quite simple.

body=[0, 4, 9,7,5] #the values should be a list

worksheet.append_row(body, table_range="A1:E1") 

#table_range should be range of columns in the sheet, example from A1 to E1 (A1:E1)
other parameters are optional. 

this will append the values in body to the last row in the sheet and it will not overwrite existing data.
like image 100
CodeRed Avatar answered Oct 22 '25 05:10

CodeRed