2017-02-22 103 views
0

enter image description here有條件的背景顏色設置爲黃色,googlesheets API

我與http://pygsheets.readthedocs.io/en/latest/index.html工作圍繞谷歌的API張V4的包裝。我有興趣使用google-sheets-api v4設置條件格式。我試圖使用自定義公式來突出顯示基於行中「Q」列的值的行。如果q列包含'TRASH',我想爲行着黃色。

正如我期待通過https://github.com/nithinmurali/pygsheets/blob/master/pygsheets/client.py的pygheets庫和sh_batch_update方法

而且,我有https://developers.google.com/sheets/api/samples/conditional-formatting#add_a_conditional_formatting_rule_to_a_set_of_ranges在此基礎上,我有:

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 
      } 
     } 

當我運行:

gc.sh_batch_update(ssheet.id,cfr1(ws.id)) 

我得到:

"Invalid JSON payload received. Unknown name "yellow" at 'requests[0].add_conditional_format_rule.rule.boolean_rule.format.background_color': Cannot find field."> 

這適用於原色綠色,紅色和藍色。如何格式化爲黃色背景。

回答

1

你不能有黃色的顏色,它應該是RGB格式,見this。所以,對於黃色,你需要紅色= 1,綠色= 1,藍色= 0

+0

非常感謝。 – user61629