[reportlab-users] Building Paragraph From Database Record

Robin Becker robin at reportlab.com
Mon Jul 2 13:28:35 EDT 2007


Rich Shepard wrote:

> I use pysqlite to retrieve records from database tables and put them in a

> list of tuples. I would like to display these values (by row) as a

> paragraph

> within a table cell with the parameter name (in bold) and the parameter

> value, and each pair separated by a semi-colon.

>

> For example, a column named 'Variables' would have a cell with contents

> like this:

>

> Name: 'Soil depth'; Description: 'Surface through C horizon';

> Component: 'Slope stability'; Sub-component: 'None'; Data

> source: 'External'; Scale: '0-50'; Method: 'Centroid';

> etc.

>

> Can I do this with code similar to this;

>

> style = styleSheet['BodyText']

> for i in len(range(self.data)):

> story.append(Paragraph(label[i], + '; ' +self.data[i]))

>

> if I have the lables also in a list?

>

> In a similar situation, can I use the newline, '\n,' in a single

> paragraph

> combining labels and their values? What I now have is this:

.........

In the latest paragraph you can use a <br/> tag to force a newline into the
outcome. Normally Paragraphs treat all space characters the same ie as places
for splitting or separating words. You shold be able to do

Paragraph('<b>Head1</b>: text1<br/><b>Head2</b>: text2.....',style) etc and have
the text laid out as you suggest. A typical way So I suspect you might want to
do this like

text = '<br/>.join(['<b>%s</b>: %s' % (label,self.data(aname))
for label, aname in [
("Project name",'model_name'),
("Project description",'model_desc'),
("Project type", 'model_type'),
("Project owner", 'proj_owner'),
("Project location, 'proj_location'),
("Project state/province", 'proj_state'),
("Lead agency", 'lead_agency'),
("Knowledge engineers", 'keName'),
]
])

If you want a fixed space you should use &nbsp;
--
Robin Becker


More information about the reportlab-users mailing list