Search code examples
pythonreportlab

Why is the column and width of a table in python creating an error


I'm creating a simple four column, one row table. However, when the code executes I receive the following error

Table 4 rows X 1 cols> with cell (0,0) containing 'D' data error - 1 columns in data but 4 in column widths".

The code is as follows:

colwidths = (46, 76, 48, 40)  
rowheights = (20)  
tabledata = ('DATE ', '3-20-2016', 'FIELD # ', '1')  
t = Table((tabledata), (colwidths), (rowheights))  

Solution

  • You simply need to wrap tabledata in another iterable to ensure its interpreted as all 5 items being on a single row, instead of 5 rows containing a single item? i.e.

    tabledata = [('DATE ', '3-20-2016', 'FIELD # ', '1')]