Skip to content Skip to sidebar Skip to footer

Update Format Of More Than One Cell With Updatecells Api Request

I'm trying to center align a range of cells, but only the first cell in the range is updated with the specified format. Here is my code: align = 'CENTER' data={ 'requests': [

Solution 1:

You want to update "AB1:AD1" ({startRowIndex: 0, endRowIndex: 1, startColumnIndex: 27, endColumnIndex: 30}). If my understanding is correct, how about this modification?

Modified points :

  • When 3 columns are updated, the values are also required to be updated. In your case, you want to update 3 columns. So it is required to create like {values: [{userEnteredFormat: ###}, {userEnteredFormat: ###}, {userEnteredFormat: ###}]}.

Modified request :

{
  "requests": 
  [
    {
      "updateCells": 
      {
        "rows": 
        [
          {
            "values": 
            [
              {
                "userEnteredFormat": 
                {
                  "horizontalAlignment": align ,   #'CENTER','LEFT','RIGHT',
                  "textFormat": 
                  {
                    "fontFamily": fontFamily,
                    "fontSize": fontSize
                  }
                }
              },
              {
                "userEnteredFormat": 
                {
                  "horizontalAlignment": align ,   #'CENTER','LEFT','RIGHT',
                  "textFormat": 
                  {
                    "fontFamily": fontFamily,
                    "fontSize": fontSize
                  }
                }
              },
              {
                "userEnteredFormat": 
                {
                  "horizontalAlignment": align ,   #'CENTER','LEFT','RIGHT',
                  "textFormat": 
                  {
                    "fontFamily": fontFamily,
                    "fontSize": fontSize
                  }
                }
              }
            ]
          }
        ],
        "range": 
        {
          "sheetId": sheetId,
          "startRowIndex": startRowIndex,
          "endRowIndex": endRowIndex,
          "startColumnIndex": startColumnIndex,
          "endColumnIndex": endColumnIndex
        },
        "fields": "userEnteredFormat",
      }
    }
  ]
}

If I misunderstand your question, please tell me. I would like to modify it.

Edit :

When you want to reflect the format for a lot of cells, you can use repeatCell. The request body is as follows. In this sample, all cells in the range are modified .

Modified request :

{
  "requests": 
  [
    {
      "repeatCell": 
      {
        "cell": 
        {
          "userEnteredFormat": 
          {
            "horizontalAlignment": align ,   #'CENTER','LEFT','RIGHT',
            "textFormat":
             {
               "fontFamily": fontFamily,
               "fontSize": fontSize
             }
          }
        },
        "range": 
        {
          "sheetId": sheetId,
          "startRowIndex": startRowIndex,
          "endRowIndex": endRowIndex,
          "startColumnIndex": startColumnIndex,
          "endColumnIndex": endColumnIndex
        },
        "fields": "userEnteredFormat"
      }
    }
  ]
}

Reference :

Post a Comment for "Update Format Of More Than One Cell With Updatecells Api Request"