我需要在网格中插入一个分界线,因为一列的值太大而无法放入PDF中:
我的代码:
for i, (_, rowCampos) in enumerate(dfBaseCampos.iterrows()):
dados.append([str(rowCampos['CAMPO']),
str(rowCampos['DESC_CAMPO']),
str(rowCampos['TIPO_CAMPO'])])
tabela = Table(dados, style=([
('GRID', (0, 0), (-1, -1), 0.25, colors.black),
('BOX', (0, 0), (-1, -1), 0.25, colors.black, None, (2, 2, 1)),
('BACKGROUND', (2, 0), (2, 0), colors.lightcyan),
('BACKGROUND', (0, 0), (0, 0), colors.lightcyan),
('BACKGROUND', (1, 0), (1, 0), colors.lightcyan),
('FONTSIZE', (0, 0), (-1, -1), 5),
('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black)
]))
答案 0 :(得分:0)
您需要使用Paragraph
之类的Flowable对象。
l1 = Paragraph("Hello python", styles['Normal'])
此解决方案对我有用:
from reportlab.platypus import Paragraph
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Table, TableStyle
from reportlab.lib import colors
styles = getSampleStyleSheet()
for i, (_, rowCampos) in enumerate(dfBaseCampos.iterrows()):
l1 = Paragraph(str(rowCampos['CAMPO']), styles['Normal'])
l2 = Paragraph(str(rowCampos['DESC_CAMPO']), styles['Normal'])
l3 = Paragraph(str(rowCampos['TIPO_CAMPO']), styles['Normal'])
dados.append([l1, l2, l3])
tabela =Table(dados)
tabela.setStyle(TableStyle([
('GRID', (0, 0), (-1, -1), 0.25, colors.black),
('BOX', (0, 0), (-1, -1), 0.25, colors.black, None, (2, 2, 1)),
('BACKGROUND', (2, 0), (2, 0), colors.lightcyan),
('BACKGROUND', (0, 0), (0, 0), colors.lightcyan),
('BACKGROUND', (1, 0), (1, 0), colors.lightcyan),
('FONTSIZE', (0, 0), (-1, -1), 5),
('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black)
]))