[reportlab-users] Table question: how do I fix the width of specific columns while ensuring that text is wrapped?

3,473 views
Skip to first unread message

Keng Onn Wong

unread,
Apr 3, 2014, 10:16:55 PM4/3/14
to reportl...@lists2.reportlab.com

Hi,

 

I am trying to generate a table that has fixed width columns, and from the documentation, I understand that this is done via passing a colWidths list of widths when the table is instantiated. E.g

 

table = Table(tableData, colWidths=[column_width1, column_width2, None, column_width3, column_width4, None]

 

and that “None” will let reportlab automatically determine the width. So far so good. However, the problem is when the text for a particular column becomes too long, and it starts accumulating all together in one messy black clump without wrapping over to the next line (within the same cell). So I tried to tackle this issue using a Paragraph Flowable, so that my tableData now looks something like this:

 

tableData = [[‘a’, ‘b’, Paragraph(“long string of text here”, some_style), ‘abc’], …]

 

However, now I find that my table, when printed out to pdf, now auto-sizes to take up the entire page width (or frame-width). Previously, when I was just using plain strings (and no Paragraph Flowables), the table took up just enough width to display the data, but now with the inclusion of the Paragraph flowable, the entire table takes up the whole width of the page/frame. Am I missing something here? Coz I would like to print a table with wrapped-around text for that fixed column but yet which fits the other data columns just right (those with ‘None’ column widths).

 

Thanks and regards,

Keng Onn

 

Reply all
Reply to author
Forward
0 new messages