Reportlab-将两个段落添加到一个表单元格中 [英] Reportlab - Add two Paragraphs into one table cell

查看:49
本文介绍了Reportlab-将两个段落添加到一个表单元格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其结构如下:

I have a table which is build up like the following:

styleN = styles["Normal"]

data = []
table_row = ['ID', 'Some Information']
data.append(table_row)

table_row = []
table_row.append(Paragraph(object.ID, styleN))
table_row.append(Paragraph(object.some_information1, styleN))

data.append(table_row)
t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), row_heights, style=ts)

现在,我想实现将第二个包含object.some_information2的段落添加到第二个单元格中的功能.

Now I want to achieve that I can add into the second cell a second paragraph containing object.some_information2.

或多或少的伪代码,以说明我要实现的目标:

Some more or less pseudo - code to illustrate what I want to achieve:

table_row = []
table_row.append(Paragraph(object.ID, styleN))
info1 = Paragraph(object.some_information1, styleN)
info2 = Paragraph(object.some_information2, styleN)
info_paragraphs = info1 + info2 
table_row.append(info_paragraphs)

data.append(table_row)
t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), row_heights, style=ts)

推荐答案

在reportlab Google组中获得反馈,实际上很容易实现.仅将段落列表添加到单元格中.

Got feedback in the reportlab google group and it is actually very easy to achieve. Only add a list of paragraphs into the cell.

styleN = styles["Normal"]
data = []
table_row = ['ID', 'Some Information']
data.append(table_row)
table_row = []
table_row.append(Paragraph(object.ID, styleN))
paragraphs = []
info1 = Paragraph(object.some_information1, styleN)
info2 = Paragraph(object.some_information2, styleN)
paragraphs.append(info1)
paragraphs.append(info2)
table_row.append(paragraphs)
data.append(table_row)
t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), None, style=ts)

这篇关于Reportlab-将两个段落添加到一个表单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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