I am trying to create a Invoice template using reportlab. For the line items in the invoice, I am using a Table. The first row of the table contains the headers and the subsequent rows will be the actual line items. What I basically want to achieve is that if the table contains only 1 line item (plus one row of header), the table should span the entire page.
How can that be done? I don't see any way of specifying the height of the rows individually.
Thanks in advance.
Change row height To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.
As mentioned, you can use 'VALIGN' to wrap text within the cells, but there is another hack if you want to further control the table elements on the canvas. rowHeights attribute. _argH for finer editing of the row heights.
Select the row or rows that you want to change. On the Home tab, in the Cells group, click Format. Under Cell Size, click Row Height. In the Row height box, type the value that you want, and then click OK.
You can specify each row heights when creating a Table object :
rows = [["Header1", "Header2"], ["Data1", "Data2"]]
table = Table(rows, colWidths=(50*mm, 50*mm), rowHeights=(10*mm, 250*mm))
To control text alignment in table cells, you can use TableStyle.
You can achieve this using TableStyles
and SPAN
commands. You can read more about how this works starting on page 81 of the ReportLab user manual. This will let you have cells span as many rows and columns as you want.
You can also use TableStyles
to adjust things like the width and hight of each row and column, but from your description that doesn't sound like what you really wanted to do.
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