本文介绍了多表 (5) 一页使用 ReportLab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中有以下代码使用 ReportLab 生成两个表.有没有办法使用 ReportLab 并排放置这两个表?

I have the following code in python to generate two tables using ReportLab. Is there a way to position this two tables side by side using 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)

推荐答案

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

Create a third table that will serve as the shell for the two tables you created. This table will have two columns and one row. Each column will be the size of the respective child table.

示例:

在不同的表变量中创建两个表(例如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])

这篇关于多表 (5) 一页使用 ReportLab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:17