[reportlab-users] Help with wordwrap in Table

Arnau Sellares arnausellares at gmail.com
Tue Dec 18 04:06:00 EST 2018


Hi Amy,

For the total width of the table, you could use the colWidths as an
argument of LongTable to determine the width of each column in the table.
As specified in the reportlab User Guide:

The other arguments are fairly obvious, the colWidths argument is a
sequence of numbers or possibly
None, representing the widths of the columns. The number of elements in
colWidths determines the
number of columns in the table. A value of None means that the
corresponding column width should be
calculated automatically.

For the wordwrap, you will need to convert the different strings in the data
object to Paragraph instances with a style (you already imported the class
and created a styleN, which you are not using :P), and it will
automatically wrap to the specified column width you determined with
colWidths.

Hope this helps
Arnau

On Tue, 18 Dec 2018 at 08:39, Lea Kaminski <Amy_658 at hotmail.com> wrote:

> 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 A4from reportlab.lib.pagesizes import letter, cmfrom reportlab.lib.styles import getSampleStyleSheetfrom reportlab.platypus import LongTable, TableStyle, BaseDocTemplate, Frame, PageTemplatefrom reportlab.lib import colorsfrom 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
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20181218/dbf11d82/attachment-0001.html>


More information about the reportlab-users mailing list