I'm using the Table of Report Lab library to print a table on a PDF report. I would like to know if it's possible to configure the table to perform an automatic wrapping of the content of a cell.
For example, I have a text that doesn't fit on a cell inside a column. I would like that the table performs the wrap automatically adjusting the content of the cells to fit on the columns width. Is it possible?
You can put any flowable in a table element. It is probably good practice to have all table elements as flowables, so they can be styled the same. For your case you will most likely need a Paragraph flowable. eg.
styles = getSampleStyleSheet()
text = Paragraph("long line",
styles['Normal'])
You can put `text' into the data you feed to a table and it will automatically wrap.
My solution, force newline in the string:
def __chopLine(line, maxline):
cant = len(line) / maxline
cant += 1
strline = ""
index = maxline
for i in range(1,cant):
index = maxline * i
strline += "%s\n" %(line[(index-maxline):index])
strline += "%s\n" %(line[index:])
return strline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With