I have been trying/looking to solve this problem for a long while. I have read the documentation for gspread and I cannot find that there is a way to rename a worksheet. Any of
This is an extraction of a library which I've coded personally:
def _batch(self, requests):
body = {
'requests': requests
}
return self._service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body).execute()
def renameSheet(self, sheetId, newName):
return self._batch({
"updateSheetProperties": {
"properties": {
"sheetId": sheetId,
"title": newName,
},
"fields": "title",
}
})
I think that with a little effort, you can implement it into your code and obtain what you want.
In order to make the batchUpdate
call, you will need the spreadsheetId as well as the initialized service
as explained in the Python QUickstart - Google Sheet API