I wanna use google api to update the background color of a cell in a spreadsheet with batchupdate
function.
https://developers.google.com/sheets/api/reference/r
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
service = build('sheets', 'v4', credentials=creds)
spreadsheetId = "###" # Please set Spreadsheet ID
sheetId = "###" # Please set sheet ID.
body = {
"requests": [
{
"updateCells": {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": 1,
"startColumnIndex": 0,
"endColumnIndex": 1
},
"rows": [
{
"values": [
{
"userEnteredFormat": {
"backgroundColor": {
"red": 1
}
}
}
]
}
],
"fields": "userEnteredFormat.backgroundColor"
}
}
]
}
res = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body).execute()
startRowIndex: 0, endRowIndex: 1m startColumnIndex: 0, endColumnIndex: 1
means the cell "A1".If I misunderstood your question and this was not the direction you want, I apologize.
You can use simple basic format for changing background color of the cell :
worksheet.format("A2:B2", {
"backgroundColor": {
"red": 0.0,
"green": 0.0,
"blue": 0.0
}