[reportlab-users] Zebra Stripes and the Table Flowable

Robin Becker robin at reportlab.com
Mon Jan 14 12:52:46 EST 2008


shawn a wrote:

> Hello,

>

> I am looking for a way to give my table flowables a "zebra striping"

> effect. I.E every other row is light gray.

>

> If i was drawing an HTML table i would simply do a

> if(rowNum mod 2 == 0):change style

>

> It doesn't look like i can get that level of control during the table draw.

> I'm sure someone has figured this out. Any insight would be greatly appreciated

>

> thanks,

> -shawn

.......there is a setting that does exactly this that does this. See
test_platypus_tables.py




######################
lst.append(Paragraph('Trying colour cycling in background',
styleSheet['Heading1']))
lst.append(Paragraph("This should alternate pale blue and uncolored by row",
styleSheet['BodyText']))
data= [['001', '01', '02', '03', '04', '05'],
['002', '01', '02', '03', '04', '05'],
['003', '01', '02', '03', '04', '05'],
['004', '01', '02', '03', '04', '05'],
['005', '01', '02', '03', '04', '05'],
['006', '01', '02', '03', '04', '05'],
['007', '01', '02', '03', '04', '05'],
['008', '01', '02', '03', '04', '05'],
['009', '01', '02', '03', '04', '05'],
['010', '01', '02', '03', '04', '05'],

]
t=Table(data,style=[
('GRID',(0,0),(-1,-1),0.5,colors.grey),
('ROWBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, None)),
])
lst.append(t)
lst.append(Spacer(0,6))
lst.append(Paragraph("And this should pale blue, pale pink and None by column",
styleSheet['BodyText']))
data= [['001', '01', '02', '03', '04', '05'],
['002', '01', '02', '03', '04', '05'],
['003', '01', '02', '03', '04', '05'],
['004', '01', '02', '03', '04', '05'],
['005', '01', '02', '03', '04', '05'],
['006', '01', '02', '03', '04', '05'],
['007', '01', '02', '03', '04', '05'],
['008', '01', '02', '03', '04', '05'],
['009', '01', '02', '03', '04', '05'],
['010', '01', '02', '03', '04', '05'],

]
t=Table(data,style=[
('GRID',(0,0),(-1,-1),0.5,colors.grey),
('COLBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, 0xFFD0D0, None)),
])
lst.append(t)
######################
--
Robin Becker


More information about the reportlab-users mailing list