问题
I am trying to layout a table in reportLab in the following format. The table is dynamic and can have many rows.
---------
| a | b |
|---| |
| a | |
|---| |
| a | |
---------
tTableStyle=[ ('SPAN',(1,0),(1,-1)) ]
Works beautifully if the table fits on one page but crashes if the table is split over pages. Without the span the table splits ok but I'm stuck with the gridlines in the second column.
Have read here that this is due to the algorithm used not being able to SPAN across pages automatically but not sure about how to work around this problem.
Is it possible to get the number of rows displayed on each page and use that instead of -1? eg. x=rows_on_page1, y=rows_on_page2 then in the tableStyle I could do something like
('SPAN',(1,0),(1, x)),
('SPAN',(1,x+1),(1,y))
It's been suggested to manually create the table but I'm not sure how. Any help is appreciated.
回答1:
The solution I ended up using was to ignore trying to span and just use the box code to draw the lines I wanted.
('INNERGRID', (0,0), (0,-1), colors.grey), # gridlines for first column
('BOX', (0,0), (-1,-1), 0.25, colors.grey), # outer border
('BOX', (0,0), (0,-1), 0.25, colors.grey), # inner border
("LINEBELOW", (0, 'splitlast'), (-1, 'splitlast'), 0, colors.grey), # draw bottom line on table split
来源:https://stackoverflow.com/questions/13812603/reportlab-table-with-a-column-spanning-all-rows-split-across-pdf-page