Andrei dev
Andrei dev

Reputation: 55

Format cells with RGBA colors via API calls

I'm using Google Sheets v4 API and I want to use the color orange FF9900 which is available on Google Sheets UI, but RGBA in the API is not following the standard color RGBA. From this tool, I get rgba(236, 161, 51, 1) for the orange color.

Here is my request code using the Google APIs Explorer:

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

However, the output on the sheet is blue and not orange as intended.

Upvotes: 2

Views: 1707

Answers (2)

Opalosolo
Opalosolo

Reputation: 261

Google use "0 to 1" scale for RGBA.

Use division by 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)'
      }
    }
  ]
}

Upvotes: 7

pnuts
pnuts

Reputation: 59460

Seems Sheets may follow precedent from Excel where the nibbles are reversed (BGR rather than RGB). Please try:

              red: 51, 
              green: 161, 
              blue: 236

Upvotes: -2

Related Questions