[reportlab-users] reportlab question

Lionel Roubeyrie reportlab-users@reportlab.com
Thu, 9 Sep 2004 15:09:34 +0200


Thanks for the help, all works right now.=20
Lionel
Le jeudi 9 Septembre 2004 14:46, Robin Becker a =E9crit=A0:
> Lionel Roubeyrie wrote:
> > Hello all,
> > I try to plot a table on a canvas with the Table module, but it cries f=
or
> > an unexisting method :-(
> > My code :
> > ####################################
> > from reportlab.pdfgen import canvas
> > from reportlab.platypus import Table, TableStyle
> > from reportlab.lib.pagesizes import A4
> > from reportlab.lib.colors import green, orange, red, black
> >
> > def box(c, h, a, d):
> >  ''' Presentation des valeurs de hier, aujourdhui et demain'''
> >  data =3D  [["hier", "aujourd'hui", " demain"],
> >     [str(h), str(a), str(d)]]
> >  t =3D Table(data)
> >  t.setStyle(TableStyle([('ALIGN', (0,0), (-1,-1), 'CENTER'),
> >       ('VALIGN', (0,0), (-1,-1), 'MIDDLE'),
> >       ('FONT',(0,0), (-1,-1), ('helvetica', 12)),
> >       ('INNERGRID', (0,0), (-1,-1), 1, black),
> >       ('BOX', (0,0), (-1,-1), 2, black)]))
> >  t.drawOn(c, 100,100)
> >
> > c=3Dcanvas.Canvas("test.pdf", pagesize=3DA4)
> > box(c,5,6,7)
> > c.showPage()
> > c.save()
>
> ......
>
> >     ecp =3D self._colpositions[sc:ec+2]
> > AttributeError: Table instance has no attribute '_colpositions'
> >
> > Argggggggggg!
>
> OK you need to call the tables wrapOn method to establish its dimensions
> before you call the drawOn method. Flowables are packed handled by some
> kind of layout engine which calls the wrap and then the draw method.
>
> in box you need to decide how the table should be wrapped by giving it so=
me
> space to use up.
>
> EG
>    w, h =3D t.wrapOn(c,400,100)
>
> use a maximum of 400 points width and 100 height.
>
> I recommend you look at how the test_platypus_tables.py script does tables
> to see a simpler way to lay out tables. The above looks simple, but is a
> bag of worms when more dynamic tables are being used.

=2D-=20
Lionel Roubeyrie - lroubeyrie@limair.asso.fr
LIMAIR
http://www.limair.asso.fr