Search code examples
pythongoogle-sheetsgspread

highlight cell with gspread in python


I am trying to use python to access a google spreadsheet, and then highlight a cell. I tried getting the Team Color addon. It lets you type the hex value of a color, and then it highlights the cell with that color. If I directly type on the spreadsheet, it works. But using this code, it doesn't for some reason:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('<json file>'))
scope = ['https://spreadsheets.google.com/feeds']

credentials = SignedJwtAssertionCredentials(json_key['client_email'],          json_key['private_key'], scope)

gc = gspread.authorize(credentials)

worksheet = gc.open("<spreadsheet name>").get_worksheet(2)

worksheet.update_acell('K2', '#FFFF00')

Can someone please let me know why the code doesn't work and/or another way to do what I am trying to accomplish?


Solution

  • Becoz Team Color listen on edit event, your code won't trigger the event and therefore Team Color can not update cell's color. Instead, you could select those cells, launch Team Color's menu (Add-ons -> Team Color -> Color), then press "Restore" button.