How do I define a style for even and odd rows of a table (python reportlab) -
i have print report may hundreds rows in length. particularity each item's content should printed on 2 lines. lines have specific style.
sample :
line 1 : first header line line 2 : second header line line 3 : name , adress line 4 : birth date , gender, hobbies line 5 : name , adress line 6 : birth date , gender, hobbies ...
i use table handle per page content.
in style definition, have this:
('fontsize',(0,2),(-1,-1),18)
but want style applies rows , style 1
('fontsize',(0,2),(-1,1),12)
applies odds rows.
the best 2 styles applies on whole table except first , second row contains header of table.
you can having code generates table style based on row number. reportlab have built-in feature automatically alternating background colors rows , colors (look rowbackgrounds
, colbackgrounds
in user manual), arbitrary styles you'll have custom following looping through data rows.
table_style = [...] i, row in enumerate(table_rows): if % 2 == 0: table_style.append(('fontsize',(0,i),(-1,i),18)) else: table_style.append(('fontsize',(0,i),(-1,i),12)) my_table.setstyle(tablestyle(table_style))
Comments
Post a Comment