[reportlab-users] Python ReportLab use of splitfirst/splitlast

Jessup, David DJESSUP at usnews.com
Thu Sep 25 12:04:07 EDT 2008


Just to follow up on my previous e-mail:

First, the documentation flat out lies where it reads "In any style
command the first row index may be set to one of the special strings
'splitlast' or 'splitfirst' to indicate that the style should be used
only for the last row of a split table, or the first row of a
continuation." In the current release, the "splitlast" and "splitfirst"
row indices break with the aforementioned TypeErrors on the TEXTCOLOR
and BACKGROUND commnds.

My suspicion, based on reading the source code, is that only the
tablestyle line commands (GRID, BOX, LINEABOVE, and LINEBELOW) are
currently compatible with the 'splitfirst' and 'splitlast' row indices.
I suspect that all cell commands break with the aforementioned
TypeErrors.

However, I was able to do what I wanted by subclassing the Table class
and overriding the onSplit method. Here is my code:

class XTable(Table):
def onSplit(self, T, byRow=1):
T.setStyle(TableStyle([
('TEXTCOLOR', (0, 1), (1, 1), colors.black)]))

What this does is apply the text color black to the first and second
cell of the second row of each page. (The first row is a header,
repeated by the repeatRows parameter of the Table.) More precisely, it
is doing this to the first and second cell of each frame, but since I am
using the SimpleDocTemplate, frames and pages are identical.

-----Original Message-----
From: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] On Behalf Of Jessup,
David
Sent: Wednesday, September 17, 2008 4:36 PM
To: reportlab-users at reportlab.com
Subject: [reportlab-users] Python ReportLab use of splitfirst/splitlast

I'm trying to use Python with ReportLab 2.2 to create a PDF report.
According to the user guide at
http://www.reportlab.com/docs/userguide.pdf,


> Special TableStyle Indeces [sic]

>

> In any style command the first row index may be set to one of the

> special strings 'splitlast' or 'splitfirst' to indicate that the

> style should be used only for the last row of a split table, or the

> first row of a continuation. This allows splitting tables with nicer

> effects around the split.


I've tried to use splitfirst to create some special formatting for the
first row on a page:

main_table.setStyle(TableStyle([
('TEXTCOLOR', (0, 'splitfirst'), (1, 0), colors.black),
]))

and it breaks with the message:


> Traceback (most recent call last):

> File "./photo_payments_report.py", line 307, in <module>

> pdfize_data(data=payment_data, output_filename=output_filename)

> File "./photo_payments_report.py", line 128, in pdfize_data

> ('TEXTCOLOR', (0, 'splitfirst'), (1, 0), colors.black),

> File

"/usr/local/lib/python2.5/site-packages/reportlab/platypus/tables.py",
line 931, in setStyle

> self._addCommand(cmd)

> File

"/usr/local/lib/python2.5/site-packages/reportlab/platypus/tables.py",
line 992, in _addCommand

> for i in xrange(sr, er+1):

> TypeError: an integer is required


Is this functionality simply broken or am I doing something wrong? If
the latter, what am I doing wrong?


_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users


More information about the reportlab-users mailing list