[reportlab-users] Sum of integer values in a table

Asif Jamadar asif.jamadar at rezayat.net
Wed Jun 29 01:10:39 EDT 2011


Hi,

I have a table which is generated dynamically, in which one field consist of integer value. Now I want to calculate the sum of that value field. Here the value field is dynamic

def some_view(request):

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
doc = SimpleDocTemplate(response)
Catalog = []
header = Paragraph("Product Inventory", styles['Heading1'])
Catalog.append(header)
style = styles['Normal']
headings = ('Product Name', 'Product Description' 'Value')
allproducts = [(p.name, p.description, p.value) for p in Product.objects.all()]
t = Table([headings] + allproducts)
t.setStyle(TableStyle([('GRID', (0,0), (1,-1), 2, colors.black),
('LINEBELOW', (0,0), (-1,0), 2, colors.red),
('BACKGROUND', (0, 0), (-1, 0), colors.pink)]))
Catalog.append(t)
doc.build(Catalog)
return response

Here the value field is integer field which consist of values.

At the end of table we want to generate the sum of value field (adding all the value field). How it can be achieved? Any solution?




More information about the reportlab-users mailing list