Using reportlab 3.1.44 I'm trying to align the table to the left (the whole table on the page, not the cells). Here is my code:
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.tables import Table, TableStyle
from reportlab.lib import colors
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT
doc = SimpleDocTemplate('sample2.pdf', showBoundary=1)
t = Table(
(('','North','South','East','West'),
('Quarter 1',100,200,300,400),
('Quarter 2',100,400,600,800),
('Total',300,600,900,'1,200')),
(72,36,36,36,36),
(24,16,16,18)
)
t.setStyle(
TableStyle([
('HALIGN',(0,0),(-1,-1),'LEFT'),\
('GRID', (0,0), (-1,-1), 0.25, colors.red, None, (2,2,1)),
('BOX', (0,0), (-1,-1), 0.25, colors.blue),
])
)
t.alignment = TA_LEFT
story = [t]
doc.build(story)
It still remains aligned to center. Any ideas how to fix this?
Apparently the TableStyle approach does not work. Here is how I got it working:
t = Table((('','North','South','East','West'),
('Quarter 1',100,200,300,400),
('Quarter 2',100,400,600,800),
('Total',300,600,900,'1,200')),
(72,36,36,36,36),
(24, 16,16,18)
,hAlign='LEFT')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With