This is a continuation of my previous question. You can check It here. So I got the tables figured out more but I cant find a way to get the width of the cells so all of the strings (dont count the header cell, I want it to be as wide as the longest value from the column) would fit in them just perfectly and set it for the whole column.
Also is there a way to start placing a table in a differen position based on the width that has been set for all the columns(I was thinking about a tuple to which you add a vaule on every iteration). I want to start the table where the arrow is. The table_data would be just one row and 4 columns with one column being empty:
table_data = ["razem", " ", " 10,03zl ", " 74,51 "]
You can find the whole code and data in the previous question thanks to help of frankfalse.
I thought about something like getting the longest string from a column and setting the width based on that.
For example in my table there's a value "bulka tarta" which is the longest string in the whole table_data beside "Nazwa Uslugi/Towaru" which is a header.
But I couldn't work it out in code
I suggest you a solution where you set the width of the column of the table for all the column of the table and, after that, you adjust the height of each row.
This is exactly the solution which I have proposed to you in your previous post for the header of the table.
In the code below I have added two example rows to your
datalist:bulka tarta XXXXX. This string can't be placed in the width column selected for all the column. So the height of the entire row is increased;data, contains the stringsmietana abcd 123456 abcdefwhich is contained in a multicell with 4 lines.Following picture show you the resulting table contained in the file
testing.pdf:I advise you that this answer is not suited for all possible the strings; for example is not suited for the string
bulka tartaXXXXXbecause the wordtartaXXXXXis longer than the width of the column.If your
datalist contains some words longer than the value:I suggest you to increase the value of
col_width.