简体   繁体   中英

Appending data on to a Google Spread-Sheet with gspread

Problem: I am trying to append data on to a Google spreadsheet. I cannot seem to append the data on to the following line. For example if the spread sheet has x rows on column A (so the last cell that has data is A x ), I would like to add the next data into column A row x+1 .

Code: Here is a snippet of my [Python] code:

spreadsheets = gc.openall()

sp1 = gc.open_by_url('https://docs.google.com/spreadsheets/d/1xRn...qNfU/edit#gid=0')

wks = gc.open('TEST SHEET').sheet1

#value_held = wks.cell(1, 1)

#print value_held

wks.update_acell('F7',"Test")

Question: So in the snippet above wks.update_acell('F7',"Test") appends "Test" into F7 only. I want to the "TEST" to be printed on F7, and when the code is run again, "TEST" to be printed on F8 ...... "TEST" to be printed on F9, and so on and so forth. Q: How can I make it so that I can print it on column "F" but the row value increases.

Research: I have been scrolling through gspread trying to find a solution but I couldn't just yet.

You can also change a cell's value via

 worksheet.update_cell(row, col, text)

Using a for loop in which row is a fixed int value (6 corresponds to column F) and col is incremented every iteration should do the trick!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM