Reputation: 36247
I'm working with http://pygsheets.readthedocs.io/en/latest/index.html a wrapper around the google sheets api v4. I am interested in setting conditional formatting using the google-sheets-api v4. I'm trying to use a custom formula to highlight a row based on the value of the "Q" column in the row. if the q column contains 'TRASH', I want to colour the row yellow.
As I look through the pygheets library in https://github.com/nithinmurali/pygsheets/blob/master/pygsheets/client.py and the sh_batch_update method
Further, I have https://developers.google.com/sheets/api/samples/conditional-formatting#add_a_conditional_formatting_rule_to_a_set_of_ranges Based on this I have:
import pygsheets
def cfr1(sheetId):
# Apply to range: A1:R
# Format cells if...: Custom formula is
# (formula:) =$Q1="TRASH"
return {
"addConditionalFormatRule": {
"rule": {
"ranges": [
{
"sheetId": sheetId,
"startColumnIndex": 'A',
"endColumnIndex": 'R',
"startRowIndex": 1,
"endRowIndex": 8
}
],
"booleanRule": {
"condition": {
"type": "CUSTOM_FORMULA",
"values": [
{
"userEnteredValue": '=$Q1="TRASH"'
}
]
},
"format": {
"backgroundColor": {
"yellow": 1.0
# "green": 0.0,
# "blue": 0.0
}
}
}
},
"index": 0
}
}
when I run:
gc.sh_batch_update(ssheet.id,cfr1(ws.id))
I'm getting:
"Invalid JSON payload received. Unknown name "yellow" at 'requests[0].add_conditional_format_rule.rule.boolean_rule.format.background_color': Cannot find field.">
This does work for primary colours green, red and blue. How do I format to a yellow background.
Upvotes: 0
Views: 1888