Skip to content Skip to sidebar Skip to footer

How Can I Change The Color Of A Worksheet's Tab

I have a python script that is pulling data from an external resource and adding data to a Google Sheet. For the most part I have everything working, except I'd like to change the

Solution 1:

I believe your goal as follows.

  • You want to change the tab color of Google Spreadsheet using gspread.
  • You want to insert new sheet using sheet.duplicate_sheet(template_id, insert_sheet_index=0, new_sheet_name=title) and want to change the tab color of the new sheet.

Modification points:

  • In this case, the sheet ID can be retrieved with new_tab.id. You can use this value to the request body.
  • In your situation, I think that tabColor instead of * can be used as the value of fields.
    • I thought that this might be the reason of your issue. Because when * is used, other fields except for tabColor are also changed.

When above points are reflected to your script, it becomes as follows.

Modified script:

Please modify body as follows and test it again.

body = {
    "requests": [
        {
            "updateSheetProperties": {
                "properties": {
                    "sheetId": new_tab.id,
                    # "title": title, # In this case, I think that this might not be required to be used.
                    "tabColor": {
                        "red": 1.0,
                        "green": 0.3,
                        "blue": 0.4
                    }
                },
                "fields": "tabColor"
            }
        }
    ]
}

References:

Post a Comment for "How Can I Change The Color Of A Worksheet's Tab"