[reportlab-users] TableStyle Alternating the background color

Dinu Gherman gherman at darwin.in-berlin.de
Fri Jul 10 02:25:17 EDT 2009


g.costanzi at email.it:


> How can assign ,in run time, a different colour to the rows of a

> table when I set the TableStile?

> I use a recordset extract from SQLite and depending on a value of a

> record field, I would like to set a different color.

> My code,rs is the recordset,if the Price value is > 5000 the I would

> like

> to change color in red.



You look at the data and set the style of the appropriate row
accordingly, something like this (untested):

...
tab_sty = [...]
for i, row in enumerate(rs):
if row[*some_index*] > 5000:
tab_sty.append(("BACKGROUND", (0,i),(-1,i), colors.red))
t.setStyle(TableStyle(tab_sty))
...

Regards,

Dinu

......................................................................
Follow me on Twitter: http://twitter.com/dinugherman



More information about the reportlab-users mailing list