Reputation: 1
All I want to do is delete a specific cell and shift up, I can't find the answer in the docs.
I can find a cells value easy enough, sheet.cell(X,Y).value
I can delete a row easy enough sheet.delete_row(Z)
And in the UI I can replicate the action I want
But I cant figure out how to do this action with gspread python
Upvotes: 0
Views: 735
Reputation: 201553
I believe your goal and situation as follows.
In this case, the method of batch_update()
of gspread is used. The simple sample script is as follows.
In this sample script, the cell "A2" is deleted, and the cells after A3 are shifted up. Please set the range as the GridRange.
spreadsheetId = "###" # Please set Spreadsheet ID.
sheetName = "Sheet1" # Please set sheet name.
client = gspread.authorize(credentials)
spreadsheet = client.open_by_key(spreadsheetId)
sheetId = spreadsheet.worksheet(sheetName)._properties['sheetId']
requests = [
{
'deleteRange': {
'range': {
'sheetId': sheetId,
'startRowIndex': 1,
'endRowIndex': 2,
'startColumnIndex': 0,
'endColumnIndex': 1,
},
'shiftDimension': 'ROWS',
}
}
]
spreadsheet.batch_update({'requests': requests})
Upvotes: 1