[reportlab-users] small bug in setting tablestyle ???
James Yoo
james.yoo at gmail.com
Wed Feb 4 12:51:27 EST 2009
Hello list,
disclaimer: I'm new to both python AND reportlab
I /think/* I may have found a small bug in the tables.py... I couldn't find
any other information relevant to my particular scenario, so I'm inclined to
believe that mine is an edge case, and perhaps a bit contrived since the
table style documentation seems to assume that one will always be setting a
style in a table on a range of cells, or aways referencing the last row or
column with -1
Nevertheless, here's the scenario:
1) I am dynamically creating a list of lists to feed to platypus.Table and
also conditionally setting table styles on a cell by cell basis...
len(data) = 3
len(data[0]) = 2
so, 3 rows, 2 cols.
2) if you happen to be setting style for a single cell in the last column
data[0][1]
eg: TableStyle.add('FONT', (1,0),(1,0), 'Times-Bold')
tables._addCommand does this test to calculate the cell coords for the
style:
873 else:
874 (op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:]
875 if sc < 0: sc = sc + self._ncols
876 if ec < 0: ec = ec + self._ncols
877 if sr < 0: sr = sr + self._nrows
878 if er < 0: er = er + self._nrows
* 879 for i in range(sr, er+1):
* *880* * for j in range(sc, ec+1):*
881 _setCellStyle(self._cellStyles, i, j, op,
values)
you'll get a list index out of range error because of the the range() in
line 880
It's simply not checking that your "end column" is actually the index for
the last column and NOT -1
Of course, I can work around this in my own code, but it seems like a
relatively minor fix to the code above or a minor adjustment to the
documentation.
- James
* maybe it is a feature...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090204/0ac293fc/attachment.html>
More information about the reportlab-users
mailing list