ReportLab: LayoutError when cell content is too long for the page

I am trying to create a table with 7 cols. The last column contains long text that seems to create an error. It appears that when cells exceed page size, an exception is thrown.

from reportlab.lib.pagesizes import landscape, A4
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import SimpleDocTemplate, LongTable, TableStyle, Paragraph
from reportlab.lib import colors
from reportlab.lib.units import mm
from datetime import date

doc = SimpleDocTemplate(response, pagesize=A4, rightMargin=30,leftMargin=30, topMargin=30,bottomMargin=18)
doc.pagesize = landscape(A4)
elements = []

styles = getSampleStyleSheet()
cell_style = styles['BodyText']
cell_style.wordWrap = 1
cell_style.fontName = 'Courier'
cell_style.spaceBefore = 30
cell_style.spaceAfter = 30

title_style = styles['Title']
title_style.fontName = 'Courier'
title = Paragraph('Export Issue Tracker (%s)' % (date.today().isoformat()), title_style)
elements.append(title)

data2 = [[Paragraph(cell, cell_style) for cell in row] for row in data]
table = LongTable(data2, colWidths=(None, None, None, None, None, None, 50*mm))
table_style = TableStyle([('BOX', (0,0), (-1,-1), 0.25, colors.black),
                            ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                            ('FONTNAME',(0,0),(-1,-1),'Courier'),
                            ('VALIGN',(0,0),(-1,-1),'TOP'),
                            ('ALIGN',(0,0),(-1,0),'CENTER'),
                            ('TEXTCOLOR',(0,0),(-1,0), colors.yellow),
                            ('BACKGROUND', (0,0), (-1,0), colors.gray),
                            ('FONTSIZE',(0,0),(-1,-1),50)] + color_style)
table.setStyle(table_style)
elements.append(table)

doc.build(elements)

However, I get the following error:

LayoutError at /issues/export_comments/
Flowable <LongTable@0x7F5AFBBB6560 35 rows x 7 cols(tallest row 2694)> with cell(0,0) containing
u'<Paragraph at 0x7f5afbcb7ef0>9'(769.88976378 x 4782), tallest cell 2694.0 points,  too large on page 2 in frame 'normal'(769.88976378 x 535.275590551*) of template 'Later'

I have seen many posts on how to do this using KeepTogether, Spacer, LongTable, but none of them work for me.

+9
source share

Source: https://habr.com/ru/post/1623113/


All Articles