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

David VanEe david.vanee at convergent.ca
Tue Oct 29 15:43:34 EDT 2019


Hi Robin,

Thanks for the simplified example.

I would expect repeating the second row to use the original second row style. Having the values and styles not consistently repeat in split tables would likely undermine the clarity the repeated rows are meant to provide.

I hadn't noticed the repeat=1 case also lead to an unexpected style being applied. It does appear to be a bug.

Thanks,
Dave

-----Original Message-----
From: Robin Becker <robin at reportlab.com> 
Sent: October 29, 2019 1:40 AM
To: reportlab-users <reportlab-users at lists2.reportlab.com>
Cc: David VanEe <david.vanee at convergent.ca>
Subject: Re: [reportlab-users] Possible bug when using Table and repeating rows other than the zeroth

On 24/10/2019 20:24, David VanEe wrote:
> 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.
> 

Hi David,

your example is to complex for any kind of discussion; I don't have pandas or numpy installed in my test environments. 
Also use of random numbers will likely make every run different and complicates the issue.

I created a simple example to try and figure out what's going on. I just replace the data and then used the split command to make two copies of the table to see what's going on I used your table style.

I think from the colours and values that appear we can say the following

1) the values appear to be split correctly ie the second row values are repeated on page 1 and the first row values are repeated on page 2.

2) The colours seem wrong in both cases.

I'm not sure exactly what is supposed tyo happen when we repeat second row. Should it have the original second row style or should it use the first row style in the second part of a split. When we repeat leading rows it seems more obvious that we should be using exactly the same styles in part0 and part1 of a split. That doesn't seem to be happening so is probably a bug.



> 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

###############################################################################
import os
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, landscape from reportlab.platypus import Paragraph, Table, SimpleDocTemplate, PageBreak from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

styleSheet = getSampleStyleSheet()
bodyText = styleSheet['BodyText']

reportoutputfilepath = os.path.join('trepeatrows.pdf')

pdf_file = 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,0),(-1,1),colors.pink),
		 ('BACKGROUND',(0,1),(-1,1),colors.lightblue),
		 ('TEXTCOLOR',(0,0),(1,-1),colors.black),
		 ('FONTSIZE', (0,0),(-1,-1), 8),
		 ]

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'],
	]

story = []
aStory = story.append

aStory(Paragraph('The whole table',bodyText)) t = Table(data, style=ts_tables, repeatRows=(1,))
aStory(t)
t = Table(data, style=ts_tables, repeatRows=(1,)) T = t.split(4*72,60) aStory(Paragraph('The split table part 0',bodyText))
aStory(T[0])
aStory(Paragraph('The split table part 1',bodyText))
aStory(T[1])

# do the same again with repeatRows=1
aStory(PageBreak())
aStory(Paragraph('The whole table repeatRows=1',bodyText)) t = Table(data, style=ts_tables, repeatRows=1)
aStory(t)
t = Table(data, style=ts_tables, repeatRows=1) T = t.split(4*72,60) aStory(Paragraph('The split table (repeatRows=1) part 0',bodyText))
aStory(T[0])
aStory(Paragraph('The split table (repeatRows=1) part 1',bodyText))
aStory(T[1])


# Build the PDF
pdf_file.build(story)
print reportoutputfilepath
###############################################################################

> Code follows:
> 
> import os
> import pandas as pd
> import numpy as np
.........
> pdf_file.build(elements)
> print reportoutputfilepath
> 
.......


--
Robin Becker


More information about the reportlab-users mailing list