Bottom Page

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()`
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 157 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Help! - How to create a Title for a Reportlab Table crabbylou 0 184 Mar-29-2020, 09:14 PM
Last Post: crabbylou
  ReportLab Polypop77 0 147 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 485 Dec-26-2019, 05:57 AM
Last Post: buran
  cyrillic symbols in tables in reportlab. hiroz 4 1,732 Mar-20-2019, 07:42 PM
Last Post: nilamo
  Reportlab Dynamic Table Q Gutt 0 2,281 Jun-13-2018, 10:18 PM
Last Post: Gutt
  Reportlab: Add xlabel, ylabel and grid to lineplot denissanga 2 2,538 Dec-19-2017, 04:48 PM
Last Post: denissanga
  ReportLab ek5442 2 1,831 Aug-24-2017, 01:29 PM
Last Post: ek5442
  Python ReportLab ek5442 6 3,952 Mar-15-2017, 07:47 PM
Last Post: ek5442

Forum Jump:


Users browsing this thread: 1 Guest(s)