[reportlab-users] How to change Table cell font size

Mike Driscoll mdriscoll at co.marshall.ia.us
Thu Feb 16 12:04:21 EST 2012


On 2/16/2012 10:55 AM, Brenda J. Butler wrote:

> On 02/16/2012 11:46 AM, Mike Driscoll wrote:

>> Hi,

>>

>> How do I apply a smaller font size to the cells in a Table object? I've tried passing a dict to the cellStyle parameter and a CellStyle object to it, but I either get invalid index error or syntax errors. I can't find an example anywhere about that. Could someone point me in the right direction? Thanks!

>>

>> Mike Driscoll

>>

>> _______________________________________________

>> reportlab-users mailing list

>> reportlab-users at lists2.reportlab.com

>> http://two.pairlist.net/mailman/listinfo/reportlab-users

> I was just working with tables the other day, here's an example (hope it helps). I'm not sure which of the

> imports you need for this but included all my imports so you can see what they are.

>

> from reportlab.platypus import *

> from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

> from reportlab.lib.pagesizes import letter

> from reportlab.lib import colors

> from reportlab.rl_config import defaultPageSize

> from reportlab.lib.units import inch

>

> tt = Table (inv_summary_table,

> colWidths = [50, 50, 40, 50, 150])

>

> tt.setStyle (TableStyle ([

> ('BACKGROUND', (0, 0), (-1, -1), colors.lightgrey),

> ('FONTSIZE', (0, 1), (-1, 1), 14),

> ('FONTSIZE', (0, 4), (-1, 4), 14),

> ('TEXTFONT', (0, 1), (-1, 1), 'Times-Bold'),

> ('TEXTFONT', (0, 4), (-1, 4), 'Times-Bold'),

> ('ALIGNMENT', (1, 2), (1, 3), 'DECIMAL'), # hours c1 l1,2

> ('ALIGNMENT', (3, 2), (3, 3), 'DECIMAL'), # rate c3 l1,2

> ('ALIGNMENT', (4, 2), (4, 3), 'DECIMAL'), # amts c4 l1,2

> ('ALIGNMENT', (4, 4), (4, 4), 'DECIMAL'), # total amt, c4 l3

> ('SPAN', (0, 1), (4, 1)),

> ('SPAN', (2, 4), (3, 4)),

> ('RIGHTPADDING', (2, 2), (-1, -1), 20),

> ]))

>

> I found examples of this in the reportlab documentation in the tables chapter. It's a pdf file, can be downloaded from

> http://www.reportlab.com/software/documentation/

> first link under "Reportlab Toolkit" page.

>


This works for me. I was looking in the manual, but I must have been blind.

Thanks!

- Mike


More information about the reportlab-users mailing list