[reportlab-users] Tabular Form w/Platypus

Rich Shepard rshepard at appl-ecosys.com
Fri Oct 12 12:35:09 EDT 2007


I'm still not getting the insight and understanding I need to write my
reports. I've read through doctemplate.py, looked at example code, and still
haven't put it all together correctly.

Here's what I have so far:

#!/usr/bin/env python

from pysqlite2 import dbapi2 as sqlite3

from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib import colors
from reportlab.lib.units import inch
from reportlab.lib.pagesizes import LETTER, landscape, portrait
from reportlab.lib.styles import ParagraphStyle

con = sqlite3.connect('burro-breath.db', isolation_level=None)
cur = con.cursor()

cur.execute("SELECT comp1, comp2 from Pairs where pair_cat='Economic'")
EcoPairs = cur.fetchall()

cur.execute("SELECT comp1, comp2 from Pairs where pair_cat='Natural'")
NatPairs = cur.fetchall()

cur.execute("SELECT comp1, comp2 from Pairs where pair_cat='Societal'")
SocPairs = cur.fetchall()

cur.close()
con.close()

def ecoTable():
et = Table(EcoPairs, colWidths=(2*inch, 2*inch))
return et

def natTable():
nt = Table(NatPairs, colWidths=(2*inch, 2*inch))
return nt

def socTable():
st = Table(SocPairs, colWidths=(2*inch, 2*inch))
return st

formStyle = TableStyle([('ALIGN', (0,0), (-1,-1), 'LEFT'),
('FONT', (0,0), (-1,-1), 'Helvetica', 8, 9)])

styleSheet = ParagraphStyle('Headline', fontsize = 13, leading = 15, fontName = 'Times-BoldItalic')

def ecoRun():
e = ecoTable()
# e.SetStyle('formStyle')
normal = ParagraphStyle('styleSheet')
story = []
story.append("Economic Component Pairs")
story.append(ecoTable)
SimpleDocTemplate('ecoForm.pdf').build(story)

if __name__ == "__main__":
ecoRun()

"""
[(u'Jobs', u'Tax base'), (u'Jobs', u'Infrastructure'), (u'Jobs',
u'Schools'), (u'Jobs', u'Housing'), (u'Jobs', u'Medical care'), (u'Jobs',
u'Sustainability'), (u'Jobs', u'Traffic volume'), (u'Tax base',
u'Infrastructure'), (u'Tax base', u'Schools'), (u'Tax base', u'Housing'),
(u'Tax base', u'Medical care'), (u'Tax base', u'Sustainability'), (u'Tax
base', u'Traffic volume'), (u'Infrastructure', u'Schools'),
(u'Infrastructure', u'Housing'), (u'Infrastructure', u'Medical care'),
(u'Infrastructure', u'Sustainability'), (u'Infrastructure', u'Traffic
volume'), (u'Schools', u'Housing'), (u'Schools', u'Medical care'),
(u'Schools', u'Sustainability'), (u'Schools', u'Traffic volume'),
(u'Housing', u'Medical care'), (u'Housing', u'Sustainability'), (u'Housing',
u'Traffic volume'), (u'Medical care', u'Sustainability'), (u'Medical care',
u'Traffic volume'), (u'Sustainability', u'Traffic volume')]
"""

The data at the end are for testing purposes without access to the actual
database.

The python errors I see when I run the above are:

Traceback (most recent call last):
File "testRL.py", line 54, in ?
ecoRun()
File "testRL.py", line 51, in ecoRun
SimpleDocTemplate('ecoForm.pdf').build(story)
File "/usr/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py",
line 870, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File "/usr/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py",
line 702, in build
self.handle_flowable(flowables)
File "/usr/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py",
line 600, in handle_flowable
self.handle_keepWithNext(flowables)
File "/usr/lib/python2.4/site-packages/reportlab/platypus/doctemplate.py",
line 575, in handle_keepWithNext
while i<n and flowables[i].getKeepWithNext(): i += 1
AttributeError: 'str' object has no attribute 'getKeepWithNext'

More clue sticks are needed, and will be appreciated.

Rich

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863


More information about the reportlab-users mailing list