I need a breakline in the Grid, because the value of a column is too big to put in PDF:
My Code:
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)
]))
You need to use a Flowable object like Paragraph
.
l1 = Paragraph("Hello python", styles['Normal'])
This solution works for me:
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)
]))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.