subba
subba

Reputation: 1695

gspread: how to change the color of an entire row?

I have the following DataFrame:

actor          Daily Total   actor1  actor2
Day
2019-01-01     25            10       15
2019-01-02     30            15       15
Avg            27.5          12.5     15.0

While writing to a worksheet of spreadsheet, how do I change the color of entire 'Avg' row? How can I highlight it?

Upvotes: 0

Views: 6214

Answers (1)

user44875
user44875

Reputation: 396

Have the same question and found an answer (from the year 2019). We can use gspread-formatting.

pip install gspread-formatting
from gspread_formatting  import *

Suppose we've already had a worksheet, wks, from a spreadsheet

fmt = cellFormat(
backgroundColor=color(1, 1, 0), #set it to yellow
textFormat=textFormat(foregroundColor=color(1, 0, 0)),
)
#red: (1,0,0), white: (1,1,1)
row = 3
format_cell_range(wks, rowcol_to_a1(row,1)+':' + rowcol_to_a1(row, wks.col_count), fmt)

If we want to highlight the text, modify the code in cellFormat

fmt = cellFormat(
backgroundColor=color(1, 1, 0), #set it to yellow
textFormat=textFormat(foregroundColor=color(1, 0, 0)),
)

Upvotes: 2

Related Questions