通过 API 调用使用 RGBA 颜色格式化单元格

Format cells with RGBA colors via API calls

我正在使用 Google Sheets v4 API,我想使用 Google Sheets UI 上可用的橙色 FF9900,但 RGBA 在API 不遵循标准颜色 RGBA。从 this 工具中,我得到橙色的 rgba(236, 161, 51, 1)。

这是我使用 Google APIs Explorer 的请求代码:

{
        requests: [{  
          repeatCell: {
            range:{
              sheetId: correctsheetid,
              startRowIndex: 2,
              endRowIndex: 3,
            },
            cell:{
              userEnteredFormat:{
                backgroundColor: {
                  red: 236, 
                  green: 161, 
                  blue: 51
                }
              }
            },
            fields: 'userEnteredFormat(backgroundColor)'
          }
        }]
      }

但是,sheet 上的输出是蓝色的,而不是预期的橙色。

似乎表格可能遵循 Excel 的先例,其中半字节被反转(BGR 而不是 RGB)。请尝试:

              red: 51, 
              green: 161, 
              blue: 236

Google 对 RGBA 使用“0 到 1”比例。

使用除以 255

{
  requests: [
    {
      repeatCell: {
        range: {
          sheetId: correctsheetid,
          startRowIndex: 2,
          endRowIndex: 3
        },
        cell: {
          userEnteredFormat: {
            backgroundColor: {
              red: 236/255,
              green: 161/255,
              blue: 51/255
              alpha: 0.5
            }
          }
        },
        fields: 'userEnteredFormat(backgroundColor)'
      }
    }
  ]
}