Skip to content

Commit 4c28f24

Browse files
authored
Merge pull request #1095 from burnash/cgkoutzigiannis-change-tab-color
add method to change the color of a tab
2 parents 912a1b4 + f7307a7 commit 4c28f24

File tree

3 files changed

+511
-0
lines changed

3 files changed

+511
-0
lines changed

gspread/worksheet.py

+44
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ def frozen_col_count(self):
180180
"""Number of frozen columns."""
181181
return self._properties["gridProperties"].get("frozenColumnCount", 0)
182182

183+
@property
184+
def tab_color(self):
185+
"""Tab color style."""
186+
if "tabColorStyle" in self._properties:
187+
return self._properties["tabColorStyle"]["rgbColor"]
188+
return None
189+
183190
def _get_sheet_property(self, property, default_value):
184191
"""return a property of this worksheet or default value if not found"""
185192
meta = self.spreadsheet.fetch_sheet_metadata()
@@ -1157,6 +1164,43 @@ def update_title(self, title):
11571164
self._properties["title"] = title
11581165
return response
11591166

1167+
def update_tab_color(self, color):
1168+
"""Changes the worksheet's tab color.
1169+
1170+
:param dict color: The red, green and blue values of the color, between 0 and 1.
1171+
"""
1172+
body = {
1173+
"requests": [
1174+
{
1175+
"updateSheetProperties": {
1176+
"properties": {
1177+
"sheetId": self.id,
1178+
"tabColor": {
1179+
"red": color["red"],
1180+
"green": color["green"],
1181+
"blue": color["blue"],
1182+
},
1183+
"tabColorStyle": {
1184+
"rgbColor": {
1185+
"red": color["red"],
1186+
"green": color["green"],
1187+
"blue": color["blue"],
1188+
}
1189+
},
1190+
},
1191+
"fields": "tabColor,tabColorStyle",
1192+
}
1193+
}
1194+
]
1195+
}
1196+
1197+
response = self.spreadsheet.batch_update(body)
1198+
self._properties["tabColorStyle"] = {
1199+
"rgbColor": color,
1200+
}
1201+
self._properties["tabColor"] = color
1202+
return response
1203+
11601204
def update_index(self, index):
11611205
"""Updates the ``index`` property for the worksheet.
11621206

0 commit comments

Comments
 (0)