Adding page-layout-aware horizontal lines to a ReportLab table layout
I'm building a PDF using ReportLab, with a Table containing most of the content.
To help distinguish rows visually, I'd like to put a horizontal line after every row, as long as it is not the last row on a page.
To put a horizontal line after every row, I could just use a TableStyle:
style = TableStyle([
("LINEBELOW", (0,0), (-1,-1), 1, colors.black),
])
t = Table(data)
t.setStyle(style)
..but using TableStyles for this doesn't seem possible, because at that point ReportLab won't know the page layout of my content.
Is there some way of doing it with the onFirstPage
and onLaterPages
parameters to doc.build开发者_JAVA技巧
?
But it should work: that's the beauty of -1
: it will be the last row/column no matter what. The only real trick is how to eliminate the line after the last row. To do it, just change the coordinates where your "LINEBELOW" ends. That is, your tuple should look like this:
("LINEBELOW", (0, 0), (-1, -2), 1, colors.black)
This will make sure it applies up to row -2
, i.e. the next to last row. This should give you exactly what you want.
ETA 2011/4/6
Ah, what you need is splitlast
. It should work if you add a style command after your existing "LINEBELOW" command thus:
("LINEBELOW", (0, 'splitlast'), (-1, 'splitlast'), 0, colors.black)
Or pick whatever color you want, as long as you set the size to 0.
精彩评论