I have an api to color the background but when I need it to iterate over few ranges the code crash after too many calls.
So I thought on 2 optional solution:
- Rearrange the sheet so all the ranges of the same color will become one big range
- change the color api to be able to color a few ranges simultaneously.
I am having trouble execute those solutions and be grateful for help.
current API for coloring the background:
def color(self, sheet_id, red=1.0, green=1.0, blue=1.0, start_row=0, end_row=0):
try:
service = build('sheets', 'v4', credentials=self.creds)
request = {
"requests": [
{
"repeatCell": {
"range": {
"sheetId": sheet_id,
"startRowIndex": start_row,
"endRowIndex": end_row
},
"cell": {
"userEnteredFormat": {
"backgroundColor": {
"red": red,
"green": green,
"blue": blue
}
}
},
"fields": "userEnteredFormat(backgroundColor)"
}
}
]
}
return service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheet_id, body=request).execute()
except Exception as err:
handle_sheets_error("color", "general_error", err=err)
New contributor