python - 使用 ReportLab 在一页上显示多个表格 (5)

标签 python python-2.7 reportlab

我在 Python 中有以下代码使用 ReportLab 生成两个表。

有没有办法使用 ReportLab 将这两个表并排放置?

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle

doc = SimpleDocTemplate("simple_table_grid.pdf", pagesize=letter)
elements = []

data= [['00', '01', '02', '03', '04','10', '11', '12', '13', '14'],
   ['10', '11', '12', '13', '14', '10', '11', '12', '13', '14'],
   ['20', '21', '22', '23', '24', '10', '11', '12', '13', '14'],
   ['30', '31', '32', '33', '34', '10', '11', '12', '13', '14']]
   
t=Table(data,5*[0.3*inch], 4*[0.2*inch])
t.setStyle(TableStyle([
        ('BACKGROUND',(0,0),(4,0),colors.gray),
                   ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                   ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                   ]))

elements.append(t)

data= [['100', '01', '02', '03', '04'],
   ['10', '11', '12', '13', '14'],
   ['20', '21', '22', '23', '24'],
   ['30', '31', '32', '33', '34']]
   
t=Table(data,5*[0.3*inch], 4*[0.2*inch])
t.setStyle(TableStyle([
        ('BACKGROUND',(0,0),(4,0),colors.gray),
                   ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                   ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                   ]))

elements.append(t)

doc.build(elements)

最佳答案

创建第三个表,它将作为您创建的两个表的外壳。该表将有两列和一行。每列将是相应子表的大小。

例子:

在不同的表变量中创建您的两个表(例如 table1table2)

t1_w = <your first table width size>
t2_w = <your second table width size>
data = [[table1, table2]]
shell_table = Table(data, colWidths=[t1_w, t2_w])

关于python - 使用 ReportLab 在一页上显示多个表格 (5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12863517/

相关文章:

python - 在 Z3 中使用 SMT 约束时是否可以获得合法范围信息

python - 带有reportlab的编号段落

python - pyfribidi for windows 或任何其他 bidi 算法

python - kwarg 使用 mypy 解包

python - 如何在 pytest 2.5.1 中注册标记?

python-2.7 - 在sklearn python中处理逻辑回归分类器中的极端不平衡多类

python - 如何从一个设定点开始?或者停止我的内存填充

python - 不断收到错误 'list' 对象没有属性 'split'

python - 将页面布局感知水平线添加到 ReportLab 表格布局

python - Openshift绑定(bind)TCP端口