Running this following code removes all the values found in column L.
range_of_cells = worksheet.range('L:L')
for cell in range_of_cells:
cell.value = ''
worksheet.update_cells(range_of_cells)
How would I modify this code so that it clears another column, Column D. So I would be removing all the values on Column L and Column D.
I believe your goal is as follows.
In this case, how about using the batchUpdate method as follows?
spreadsheetId = "###" # Please set Spreadsheet ID.
sheetName = "Sheet1" # Please set the sheet name.
clearColumns = [4, 12] # These column numbers mean columns "D" and "L"
client = gspread.authorize(creds) # Please use your authorization script.
spreadsheet = client.open_by_key(spreadsheetId)
worksheet = spreadsheet.worksheet(sheetName)
reqs = [{
"repeatCell": {
"range": {
"sheetId": worksheet.id,
"startColumnIndex": c - 1,
"endColumnIndex": c
},
"fields": "userEnteredValue"
}
} for c in clearColumns]
res = spreadsheet.batch_update({"requests": reqs})