Python Forum
Python Reportlab Wordwrap Table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Reportlab Wordwrap Table
#1
I have a generated list in python, for having a nice layout i need a wordwrap in it. Because of beeing a list in a list I am not able to use Paragraphe () (or maybe someone know how to - i have not been able to write a functionting code)

So here the question: how can i wordwrap the text in mycells so the table fits to the page and all the text can be seen? Or can ia maybe set the width of the table so the text wordwraps itself ?

here is my code (in short):

from reportlab.lib.pagesizes import A4
from reportlab.lib.pagesizes import letter, cm
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import LongTable, TableStyle, BaseDocTemplate, Frame, PageTemplate
from reportlab.lib import colors
from reportlab.platypus import Paragraph, Table, TableStyle
########################################################################

def test():
    doc = BaseDocTemplate(
        "question.pdf",
        pagesize=A4,
        rightMargin=72,
        leftMargin=72,
        topMargin=50,
        bottomMargin=80,
        showBoundary=False)

elements = []
data = [['A', 'B', 'C', 'dddddddddddd', 'D'],
        ['00', '0dddddddddddddddddddddddddddddddddddd1', '02', 'fff', '04'],
        ['10', '11', '12', 'dfg', '14'],
        ['20', '21', '22', 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddd23', '24'],
        ]

t = LongTable(data)

tableStyle = [
    ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
    ('BOX', (0, 0), (-1, -1), 0.25, colors.black),
]
t.setStyle(TableStyle(tableStyle))
elements.append(t)

styles = getSampleStyleSheet()
styleN = styles['Normal']


frame = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height - 2 * cm, id='normal')
template = PageTemplate(id='longtable', frames=frame)
doc.addPageTemplates([template])


doc.build(elements)


if __name__ == '__main__':
    test()`
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cyrillic symbols in tables in reportlab. hiroz 5 2,446 Sep-10-2020, 04:57 AM
Last Post: bradmalcom
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 424 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  Using Reportlab to create a landscape pdf SmukasPlays 2 397 Aug-09-2020, 09:31 PM
Last Post: SmukasPlays
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 336 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Help! - How to create a Title for a Reportlab Table crabbylou 0 783 Mar-29-2020, 09:14 PM
Last Post: crabbylou
  ReportLab Polypop77 0 294 Mar-20-2020, 01:17 PM
Last Post: Polypop77
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 750 Dec-26-2019, 05:57 AM
Last Post: buran
  Reportlab Dynamic Table Q Gutt 0 2,641 Jun-13-2018, 10:18 PM
Last Post: Gutt
  Reportlab: Add xlabel, ylabel and grid to lineplot denissanga 2 2,996 Dec-19-2017, 04:48 PM
Last Post: denissanga
  ReportLab ek5442 2 2,127 Aug-24-2017, 01:29 PM
Last Post: ek5442

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020