2

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

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 的第二个段落。

一些或多或少的伪代码来说明我想要实现的目标:

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)
4

1 回答 1

4

在 reportlab google group 中得到反馈,实际上很容易实现。仅将段落列表添加到单元格中。

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)
于 2012-08-06T08:31:51.810 回答