[reportlab-users] Possible bug when using Table and repeating rows other than the zeroth

David VanEe david.vanee at convergent.ca
Thu Oct 24 15:24:51 EDT 2019


Hi,

I'm trying to use the repeatRow argument for tables, but repeating rows other than the 0th row using a tuple of row indices.

For example, the following code should repeat the 'E F G H' row on each page, including the light blue background color. The contents of the table are repeated as expected, but the formatting is that of the 0th row (not the 1st). I've taken a look at the Reportlab code (platypus\tables.py line 1375) and it looks like it should be working, so I'm not sure what's going on.

If anyone has any suggestions that'd be great.

Thanks,
Dave

Code follows:

import os
import pandas as pd
import numpy as np
import reportlab.platypus
import reportlab.lib.styles
from reportlab.lib import colors
from reportlab.lib.units import mm
from reportlab.lib.pagesizes import letter, landscape

reportoutputfilepath = os.path.join('.\\test.pdf')

pdf_file = reportlab.platypus.SimpleDocTemplate(
                            reportoutputfilepath,
                            pagesize=landscape(letter),
                            rightMargin=10,
                            leftMargin=10,
                            topMargin=38,
                            bottomMargin=23
                    )
ts_tables = [
         ('ALIGN', (4,0), (-1,-1), 'RIGHT'),
         ('LINEBELOW', (0,0), (-1,0), 1, colors.purple),
         ('FONT', (0,0), (-1,0), 'Times-Bold'),
         ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple),
         ('FONT', (0,-1), (-1,-1), 'Times-Bold'),
         ('BACKGROUND',(0,1),(-1,1),colors.lightblue),
         ('BACKGROUND',(2,2),(-2,-2),colors.white),
         ('TEXTCOLOR',(0,0),(1,-1),colors.black),
         ('FONTSIZE', (0,0),(-1,-1), 8),
         ]

df = pd.DataFrame(np.random.randint(0,50,size=(50, 4)), columns=list('ABCD'))
lista = [df.columns[:,].values.astype(str).tolist()] + ['EFGH'] + df.values.tolist()

table = reportlab.platypus.Table(lista, colWidths=(20*mm, 20*mm, 20*mm, 20*mm),repeatRows=(1,))
table_style = reportlab.platypus.TableStyle(ts_tables)
table.setStyle(table_style)
elements = []
elements.append(table)

# Build the PDF
pdf_file.build(elements)
print reportoutputfilepath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20191024/1d04276f/attachment.html>


More information about the reportlab-users mailing list