Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Reportlab Dynamic Table Q
#1
Hi, I am struggling with using a parsed JSON list as the data for a dynamic table in reportlab.

Can anyone help me out here -- below is a generic reportlab script for a table. What I need help with is using the same principle but with a list, which will always be changing, instead of the static data that is used in the example below.. Thanks for any help!

#!/usr/local/bin/python
 
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, inch, landscape
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
 
doc = SimpleDocTemplate("test_report_lab.pdf", pagesize=A4, rightMargin=30,leftMargin=30, topMargin=30,bottomMargin=18)
doc.pagesize = landscape(A4)
elements = []
 
data = [
["Letter", "Number", "Stuff", "Long stuff that should be wrapped"],
["A", "01", "ABCD", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"],
["B", "02", "CDEF", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"],
["C", "03", "SDFSDF", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"],
["D", "04", "SDFSDF", "DDDDDDDDDDDDDDDDDDDDDDDD DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"],
["E", "05", "GHJGHJGHJ", "EEEEEEEEEEEEEE EEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEEEEEE"],
]
 
#TODO: Get this line right instead of just copying it from the docs
style = TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
                       ('TEXTCOLOR',(1,1),(-2,-2),colors.red),
                       ('VALIGN',(0,0),(0,-1),'TOP'),
                       ('TEXTCOLOR',(0,0),(0,-1),colors.blue),
                       ('ALIGN',(0,-1),(-1,-1),'CENTER'),
                       ('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
                       ('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
                       ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                       ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                       ])
 
#Configure style and word wrap
s = getSampleStyleSheet()
s = s["BodyText"]
s.wordWrap = 'CJK'
data2 = [[Paragraph(cell, s) for cell in row] for row in data]
t=Table(data2)
t.setStyle(style)
 
#Send the data and build the file
elements.append(t)
doc.build(elements)
I think I need to do a list of lists... but am relatively new to python so looking for a little bump in the right direction
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 163 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  Help! - How to create a Title for a Reportlab Table crabbylou 0 203 Mar-29-2020, 09:14 PM
Last Post: crabbylou
  ReportLab Polypop77 0 153 Mar-20-2020, 01:17 PM
Last Post: Polypop77
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 495 Dec-26-2019, 05:57 AM
Last Post: buran
  cyrillic symbols in tables in reportlab. hiroz 4 1,748 Mar-20-2019, 07:42 PM
Last Post: nilamo
  Python Reportlab Wordwrap Table Mady 0 1,984 Dec-18-2018, 06:31 AM
Last Post: Mady
  Reportlab: Add xlabel, ylabel and grid to lineplot denissanga 2 2,561 Dec-19-2017, 04:48 PM
Last Post: denissanga
  ReportLab ek5442 2 1,840 Aug-24-2017, 01:29 PM
Last Post: ek5442
  Method for pulling in dynamic table data brocq_18 1 1,387 Apr-03-2017, 04:07 PM
Last Post: snippsat
  Python ReportLab ek5442 6 3,974 Mar-15-2017, 07:47 PM
Last Post: ek5442

Forum Jump:


Users browsing this thread: 1 Guest(s)