我正在使用ReportLab工具在Python中进行开发。我需要生成PDF格式的报告。数据将从数据库检索并插入表格中。 以下是简单的代码:
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from reportlab.lib.units import inch
doc = SimpleDocTemplate("simple_table.pdf", pagesize=letter)
elements = []
data= [['00', '01', '02', '03', '04'],
['10', 'Here is large field retrieve from database', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', 'Here is second value', '34']]
t=Table(data)
columnWidth = 1.9*inch;
for x in range(5):
t._argW[x]= cellWidth
elements.append(t)
doc.build(elements)
有三个问题:
- 单元格中的长数据会与同行的其他单元格重叠。
- 当我手动增加列宽度时,例如
cellWidth = 2.9*inch;
,页面不可见且无法左右滚动。 - 我不知道如何将数据追加到单元格中,也就是说,如果数据量很大,应该将其附加到同一单元格中的下一行。
我如何遇到这个问题?