Reportlab error: 'Table' object has no attribute '_colpositions' Reportlab error: 'Table' object has no attribute '_colpositions' python-3.x python-3.x

Reportlab error: 'Table' object has no attribute '_colpositions'


I think the problem is that your just passing a list. Table wants to have a list of lists e.g. a 2D-Array. From the user-guide:

The data argument is a sequence of sequences of cell values each of which should be convertible to a string value using the str function or should be a Flowable instance (such as a Paragraph) or a list (or tuple) of such instances.

If you just have one row, encapsulate that row into another list and pass that to Table. If this doesn't work, please post a minimal and also executable code example.

P.S. On page 77 of the user guide is a straightforward example of the Table-class

UPDATENow i see. You are using a Flowable which is normally supposed to go through platypus layout-engine by using it in combination with a DocTemplate. This is explained in detail in Chapter 5. You are using the manual way by drawing directly to a canvas, so you also have to code your "own" layout-engine. In this case you first have to use the wrapOn method of your Table. I don't really know why, but it doesn't seem to matter what sizes you pass as arguments. If it doesn't work, try to play with the values. Here is my adjusted version of your code:

from reportlab.pdfgen import canvasfrom reportlab.lib.units import inchfrom reportlab.platypus import Table as pdfTablefilename = 'pdf_test.pdf'p = canvas.Canvas(filename)table_data = [['a', 'b', 'c'], ['d', 'e', 'f']]top_row = pdfTable(table_data)w, h = top_row.wrapOn(p, 0, 0)top_row.drawOn(p, 0.75*inch, 0.5*inch)p.showPage()p.save()