[reportlab-users] Table example
Jessup, David
DJESSUP at usnews.com
Fri Jan 8 12:14:17 EST 2010
ReportLab has two different levels of abstraction. When you're working with the canvas object, you're at the low level. You have a lot of control, but at the cost of having to specify in great detail. The higher level is known as Platypus. The Table object is part of Platypus, so it can't interact directly with the canvas object. Instead, what you have to do is send it to a platypus document:
----------8<----------
from reportlab.platypus import SimpleDocTemplate
from reportlab.lib.pagesizes import landscape, LETTER
# code omitted, including definition of output_filename
def myPage(canvas, doc):
canvas.saveState()
# Set up the objects that are the same from page to page
canvas.restoreState()
doc = SimpleDocTemplate(output_filename, pagesize=landscape(LETTER))
# Set up your table t here
report = [t]
doc.build(report, onFirstPage=myPage, onLaterPages=myPage)
----------8<----------
________________________________
From: reportlab-users-bounces at lists2.reportlab.com [mailto:reportlab-users-bounces at lists2.reportlab.com] On Behalf Of Juan Efren Castillo
Sent: Thursday, January 07, 2010 10:26 PM
To: reportlab-users at lists2.reportlab.com
Subject: [reportlab-users] Table example
I am trying to draw a simple table.
According to docs, this will make a table
data= [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
t=Table(data)
t.setStyle(TableStyle([('BACKGROUND',(1,1),(-2,-2),colors.green),
('TEXTCOLOR',(0,0),(1,-1),colors.red)]))
How ever I am not sure how to insert it to my canvas, looking into the source I found draw and drawOn methods, how ever when I try them I get this error:
"Table instance has no attribute '_colpositions'"
How should I place my table?
Thanks.
--
Juan Efrén Castillo Encinas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100108/88a53354/attachment.htm>
More information about the reportlab-users
mailing list