I have to print a report which may be hundreds rows in length. Its particularity is that each item's content should be printed on two lines. Those lines have a 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 to handle the per page content.
In the style definition, I have something like this:
('FONTSIZE',(0,2),(-1,-1),18)
But I want that this style applies to all even rows and a style like this one
('FONTSIZE',(0,2),(-1,1),12)
applies to all odds rows.
The best would be that this two styles applies on the whole table except the first and second row which contains the header of the table.
You can do this by having code that generates the table style based on the row number. Reportlab does have a built-in feature to automatically do alternating background colors for rows and colors (look for ROWBACKGROUNDS and COLBACKGROUNDS in the user manual), but for arbitrary styles you'll have to do something custom like the following by looping through your data rows.
table_style = [...]
for i, row in enumerate(table_rows):
if i % 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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With