ReportLab 表的列跨越 PDF 页面上的所有行? [英] ReportLab table with a column spanning all rows split across PDF page?

查看:81
本文介绍了ReportLab 表的列跨越 PDF 页面上的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按以下格式在 reportLab 中布置表格.该表是动态的,可以有很多行.

---------||乙 ||---||||||---|||||---------

<块引用>

tTableStyle=[ ('SPAN',(1,0),(1,-1)) ]

如果表格适合一页,则效果很好,但如果表格被分成几页,则会崩溃.没有跨度,表格可以拆分,但我坚持使用第二列中的网格线.

已阅读此处,这是由于使用的算法无法自动跨页面 SPAN,但不确定如何解决此问题.

是否可以获取每页显示的行数并使用它而不是 -1?例如.x=rows_on_page1, y=rows_on_page2 然后在 tableStyle 我可以做类似的事情

('SPAN',(1,0),(1, x)),('SPAN',(1,x+1),(1,y))

有人建议手动创建表,但我不确定如何.任何帮助表示赞赏.

解决方案

我最终使用的解决方案是忽略试图跨越并仅使用框代码绘制我想要的线条.

('INNERGRID', (0,0), (0,-1), colours.grey), # 第一列的网格线('BOX', (0,0), (-1,-1), 0.25, colors.grey), # 外边框('BOX', (0,0), (0,-1), 0.25, colours.grey), # 内边框("LINEBELOW", (0, 'splitlast'), (-1, 'splitlast'), 0, colours.grey), # 在表格分割上画底线

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.

解决方案

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

这篇关于ReportLab 表的列跨越 PDF 页面上的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆