[reportlab-users] TableStyle Alternating the background color

g.costanzi at email.it g.costanzi at email.it
Fri Jul 10 01:08:01 EDT 2009


Hi

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.


def makeTableData(rs):

  

    count = 0

    fields = ['Product','Warehouse
Code','Supplier','Quantity','Price']

 

    for i in rs:

        count += i[4]

       

    tax = (float(count*int(cfg.dict_warehouse[4])/100))


    rs.insert(0,fields)

    rs.insert(len(rs),['','','','Total',count])

    rs.insert(len(rs),['','','','Tax',tax])

    rs.insert(len(rs),['','','','After Tax',tax+count])

   

    t = Table(rs,

             
colWidths=(200,50,50,50,50),

             
hAlign='CENTER',

             
repeatRows = 1)


    t.setStyle(TableStyle([('ALIGN',(0,0),(-1,0),'CENTER'),

                          
('ALIGN',(1,1),(-1,-1),'CENTER'),

                          
('BOX',(0,0),(-1, 0), 0.5, colors.black),

                          
('BACKGROUND',(0,0),(-1,0),colors.lightgrey),

                          
('BACKGROUND',(-1,-1),(-1,-1),colors.lightgrey),

                          
('FONT', (-1,-1), (-1,-1), 'Times-Bold'),

                          
('GRID',(0,0),(-1,-1), 0.2, colors.black),

                          
('FONT', (0,0),(-1,0),'Helvetica-Bold', 10),

                          
('VALIGN',(0,0),(-1,-1),'MIDDLE')]))

    return t


Regards.

--

Giuseppe

Errare è umano, ma per fare veramente casino ci vuole la password di
root...



--
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP
autenticato? GRATIS solo con Email.it: http://www.email.it/f

Sponsor:
GRATIS: 250 Biglietti da Visita + 1 elegante Porta biglietti metallico!
Spese di spedizione escluse. Offerta limitata, fai in fretta!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=8956&d=20090710

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090710/784f7d20/attachment.html>


More information about the reportlab-users mailing list