在reportlab中,在Table()参数内,可以用rowHeights设置单行的行高,请举例说明 ?
时间: 2023-02-17 21:25:31 浏览: 175
在reportlab中,可以使用Table()函数来创建表格。rowHeights参数可以用来设置单行的行高。举个例子,如果想要第一行行高为20,第二行行高为30,第三行行高为40,可以这样写:
```
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table
doc = SimpleDocTemplate("table.pdf", pagesize=letter)
elements = []
data = [['col1', 'col2', 'col3'],
['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9']]
t = Table(data, colWidths=[1.5*inch, 1.5*inch, 1.5*inch], rowHeights=[20, 30, 40])
t.setStyle(TableStyle([('BACKGROUND', (0, 0), (-1, 0), colors.green),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, -1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black)]))
elements.append(t)
doc.build(elements)
```
这样,第一行的行高为20,第二行的行高为30,第三行的行高为40。