[reportlab-users] Help with wordwrap in Table

Lea Kaminski Amy_658 at hotmail.com
Tue Dec 18 02:38:58 EST 2018


Hi,
i hope subcribing to the list worked. PLease let me know if not.
I need some help with setting a wordwrap in a generated list. The list always is with different content. I need to have a wordwrap for every single cell/item of the list. Also i would like to set the total width of the table to alway be the same. I would be really gald for help. I hope its right that i post my code now.


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, PageTemplatefrom 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()`

Thank you a million times for any kind of help.
Best regarts,
Amy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20181218/aa520677/attachment-0001.html>


More information about the reportlab-users mailing list