<p>I'm trying to use Python with ReportLab 2.2 to create a PDF report.<br>
According to the <a href="http://www.reportlab.com/docs/userguide.pdf" rel="noreferrer">user guide</a>,</p>

<blockquote>
  <p>Special TableStyle Indeces [sic]</p>
  
  <p>In any style command the first row index may be set to one of the special strings 'splitlast' or 'splitfirst' to indicate that the style should be used only for the last row of a split table, or the first row of a continuation. This allows splitting tables with nicer effects around the split.</p>
</blockquote>

<p>I've tried using several style elements, including:</p>

<pre><code>('TEXTCOLOR', (0, 'splitfirst'), (1, 'splitfirst'), colors.black) 
('TEXTCOLOR', (0, 'splitfirst'), (1, 0), colors.black) 
('TEXTCOLOR', (0, 'splitfirst'), (1, -1), colors.black) 
</code></pre>

<p>and none of these seems to work.  The first generates a TypeError with the message: </p>

<pre><code>TypeError: cannot concatenate 'str' and 'int' objects
</code></pre>

<p>and the latter two generate TypeErrors with the message:</p>

<pre><code>TypeError: an integer is required
</code></pre>

<p>Is this functionality simply broken or am I doing something wrong?  If the latter, what am I doing wrong?</p>

[{'answer_id': 78702, 'author': 'dF.', 'author_id': 3002, 'author_profile': 'https://Stackoverflow.com/users/3002', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>[...] In any style command <strong>the first row\n  index</strong> may be set to one of the special strings [...]</p>\n</blockquote>\n\n<p>In your first example you're setting the <em>second</em> row index to a special string as well.</p>\n\n<p>Not sure why the other two don't work... Are you sure this is where the exception is coming from?</p>\n"}, {'answer_id': 94869, 'author': 'DLJessup', 'author_id': 14382, 'author_profile': 'https://Stackoverflow.com/users/14382', 'pm_score': 2, 'selected': False, 'text': '<p>Well, it looks as if I will be answering my own question.</p>\n\n<p>First, the documentation flat out lies where it reads "In any style command the first row index may be set to one of the special strings \'splitlast\' or \'splitfirst\' to indicate that the style should be used only for the last row of a split table, or the first row of a continuation."  In the current release, the "splitlast" and "splitfirst" row indices break with the aforementioned TypeErrors on the TEXTCOLOR and BACKGROUND commnds.</p>\n\n<p>My suspicion, based on reading the source code, is that only the tablestyle line commands (GRID, BOX, LINEABOVE, and LINEBELOW) are currently compatible with the \'splitfirst\' and \'splitlast\' row indices.  I suspect that all cell commands break with the aforementioned TypeErrors.</p>\n\n<p>However, I was able to do what I wanted by subclassing the Table class and overriding the onSplit method.  Here is my code:</p>\n\n<pre><code>class XTable(Table):\n    def onSplit(self, T, byRow=1):\n        T.setStyle(TableStyle([\n          (\'TEXTCOLOR\', (0, 1), (1, 1), colors.black)]))\n</code></pre>\n\n<p>What this does is apply the text color black to the first and second cell of the second row of each page.  (The first row is a header, repeated by the repeatRows parameter of the Table.)  More precisely, it is doing this to the first and second cell of each frame, but since I am using the SimpleDocTemplate, frames and pages are identical.</p>\n'}, {'answer_id': 2623783, 'author': 'Robin Macharg', 'author_id': 314737, 'author_profile': 'https://Stackoverflow.com/users/314737', 'pm_score': 1, 'selected': False, 'text': '<p>This seems to be a bug in the ReportLab Table class.  Another fix for this in addition to <a href="https://stackoverflow.com/a/94869/669202">DLJessup\'s own answer</a> is to modify the ReportLab code that\'s causing the error, in <code>Table._drawBkgrnd()</code>, around line 1301.  For \'splitlast\', change:</p>\n\n<pre><code>y0 = rowpositions[sr]\n</code></pre>\n\n<p>to: </p>\n\n<pre><code>if sr == \'splitlast\':\n    y0 = rowpositions[-2] # last value is 0.  Second last is the one we want.\nelse:\n   y0 = rowpositions[sr]\n</code></pre>\n\n<p>This is easily done in your own code without hacking ReportLab by subclassing Table and overwriting this method.  I\'ve not had need to use \'splitfirst\'; if I do I\'ll post the rest of the hack here.</p>\n'}]
['https://Stackoverflow.com/questions/78450', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14382/']