Skip to content Skip to sidebar Skip to footer

How Can I Reset The Color Of A Google Sheet Through The Api

Building off of this question about setting a color, I wonder how to reset/clear the color of a Google Sheet's tab. For reference, here is how to set a color sheet = open_works

Solution 1:

I believe your goal as follows.

  • You want to reset the tab colors of sheets in a Google Spreadsheet.
  • You want to achieve this using gspread.

Modification point:

  • In this case, I think that to use the value of fields is an important point. When "fields": "tabColor" is used for the request body of the method of batchUpdate, the property of tabColor is modified. In that case, in order to reset the tab color, tabColor is not included in properties. By this, the tab color is reset.

When above point is reflected to the script, it becomes as follows.

Sample script:

spreadsheetId = "###"# Please set the Spreadsheet ID.

client = gspread.authorize(credentials)
spreadsheet = client.open_by_key(spreadsheetId)
sheets = spreadsheet.worksheets()
body = {"requests": [{
    "updateSheetProperties": {
        "properties": {
            "sheetId": e.id,
        },
        "fields": "tabColor"
    }
} for e in sheets]}
spreadsheet.batch_update(body)
  • In this sample script, the tab colors of all sheets in the Google Spreadsheet are reset.

Note:

  • When you want to reset the tab color of one of sheets in the Google Spreadsheet, please use the following request body.

    body = {"requests": [{
          "updateSheetProperties": {
              "properties": {
                  "sheetId": sheetId, # Please set the sheet ID.
              },
              "fields": "tabColor"
          }
      }]}
    

References:

Post a Comment for "How Can I Reset The Color Of A Google Sheet Through The Api"