[reportlab-users] determination of number of column in a table.
Robin Becker
reportlab-users@reportlab.com
Mon, 17 Feb 2003 12:02:23 +0000
In article <1045252887.26885.14.camel@eyrie.gsfc.nasa.gov>, Bryan Muir
<bmuir@eyrie.gsfc.nasa.gov> writes
>Big surprise, I have a table that is made up of rows and cols.
>
>The cols can be in any arbitrary order as they are configured by the
>user. I can generate the table fine, but often times it has more columns
>than will fir on a page. So I am in the process of implementing a
>procedure to only show the number of columns that will fot on a page.
>
>I figured out how to make the table calculate the sizes of the rows, but
>I was wondering what was the best way to calculate the number of cols.
>
>Currently, just prior to appending the table to the story, I am grabbing
>the current page size, subtracting my standard margins, and then looping
>over the column widths of the table and adding them up. When I run out
>of space, I now how many cols I can use.
>
>My question is, is there a better way of determining this information?
>Like a switch to tell the SimpleDocTemplate to ignore extra cols?
>
>If not, does anyone else have source code that implements something
>similiar that I can look at?
>
>
The table class itself has an internal method that can be used for the
purpose. Try t._calc(). After that is done you can check
1) t._width (The total width)
2) t._colpositions
Note that you must delete attributes t._width, t._width_calculated_once
to get things to behave normally again if you change t after this (ie
remove columns).
--
Robin Becker