I'm trying to add rows and delete columns trough gspread, but i keep getting TypeError: string indices must be integers
Here's the code:
writeTo = client.open_by_key(file['id']).worksheet('Sheet1')
request = {
"requests": [
{
"deleteDimension": {
"range": {
"sheetId": 0,
"dimension": "COLUMNS",
"startIndex": 8,
"endIndex": 26
}
}
}
]
}
result = writeTo.batch_update(request)
I'm using sheets API v3
batch_update
method is the method of Class gspread.spreadsheet.Spreadsheet
. Ref When I saw your script, client.open_by_key(file['id']).worksheet('Sheet1')
returnd Class gspread.worksheet.Worksheet
. I thought that this was the reason of your issue.
TypeError: string indices must be integers
occurs.When these points are reflected in your script, it becomes as follows.
writeTo = client.open_by_key(file['id']).worksheet('Sheet1')
writeTo = client.open_by_key(file['id'])
In this modification, it supposes that the value of file['id']
is the valid Spreadsheet ID. Please be careful about this. When an error like Requested entity was not found.
occurs, please confirm your Spreadsheet ID again.
And, I think that your request body is correct. When I tested your request body using the modified script, I confirmed that no error occurs.