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/rest/v4/spreadsheets/batchUpdate
what should my request be like if to update the cell sheet1!A1 with the value value and background color red.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With