I am using gspread in a python script and I have been trying to find a quick way of clearing a column in a given sheet.
Q: How can I clear the columns with gspread?
Take a look at the documentation.
You can only clear entire rows or multiple cells.
So, for a column you will need to do something like this :
worksheet = sheet.get_worksheet(0)
# Select a range (row by row)
cell_list = worksheet.range("N2:P2")
cell_list.extend(worksheet.range("N3:P3"))
cell_list.extend(worksheet.range("N4:P4"))
cell_list.extend(worksheet.range("N5:P5"))
cell_list.extend(worksheet.range("N6:P6"))
# Set the value
for cell in cell_list:
cell.value = ''
# Update in batch
worksheet.update_cells(cell_list)
This is from gspread document and it works for me. To clear a column 'A' in a google sheet from all its contain
worksheet.batch_clear(['A:A'])
I hope this is useful for someone
Clear method does not exist. You should loop through the data and
update_cell(row, col, "")
In latest version of gspread
you have the following method values_cldar it takes a range as argument and will clear this range in a single HTTP request.
It should look like:
spsh = client.open("my sheet")
spsh.values_clear("A1:P4")