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

2,882 views
Skip to first unread message

Mike Driscoll

unread,
Feb 16, 2012, 11:46:50 AM2/16/12
to reportlab-users
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
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

Brenda J. Butler

unread,
Feb 16, 2012, 11:55:46 AM2/16/12
to 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.

--
}{ Centre for Research and Experimental Development in Informatics Libre

Brenda J. Butler
b...@credil.org
+1 613 693 0684 #3202
F3018 - 283 Alexandre Taché
Gatineau (QC) J9A 1L8 CANADA
Sustainable Innovation // Innovation Durable

Mike Driscoll

unread,
Feb 16, 2012, 12:04:21 PM2/16/12
to reportl...@lists2.reportlab.com

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

Thanks!

- Mike

Reply all
Reply to author
Forward
0 new messages