Python Forum
Help! - How to create a Title for a Reportlab Table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! - How to create a Title for a Reportlab Table
#1
Hi, I am trying to create a title for my reportlab table.

from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Frame, Spacer
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.lib.pagesizes import A3, A4, landscape, portrait
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.pdfgen import canvas

try:
    #
    #   Define report name
    #
    strPDFParameterReportFile = "test.pdf"
    doc = SimpleDocTemplate(strPDFParameterReportFile, pagesize=A4)
    #
    #   Container for flowable objects
    #
    elements = []
    styles=getSampleStyleSheet()
    styleN = styles["Normal"]
    #
    #   Column headings
    #
    column1Heading = "First Name"
    column2Heading = "Last Name"
    #
    # Assemble data
    #
    data = [[column1Heading,column2Heading]]
    #
    data.append(["Moe", "Howard"])
    data.append(["Larry", "Fine"])
    data.append(["Curly", "Howard"])
    data.append(["Shemp", "Howard"])
    #
    #   Define styles
    #
    tableThatSplitsOverPages = Table(data, [6 * cm, 6 * cm], repeatRows=1)
    tableThatSplitsOverPages.hAlign = 'LEFT'
    tblStyle = TableStyle([('TEXTCOLOR',(0,0),(-1,-1),colors.black),
                           ('VALIGN',(0,0),(-1,-1),'TOP'),
                           ('LINEBELOW',(0,0),(-1,-1),1,colors.black),
                           ('BOX',(0,0),(-1,-1),1,colors.black),
                           ('BOX',(0,0),(0,-1),1,colors.black)])
    tblStyle.add('BACKGROUND',(0,0),(1,0),colors.lightblue)
    tblStyle.add('BACKGROUND',(0,1),(-1,-1),colors.white)
    tableThatSplitsOverPages.setStyle(tblStyle)
    elements.append(tableThatSplitsOverPages)
    doc.build(elements)
except:
    blnAnErrorHasOccurred = True
Any help is appreciated.

Lou
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cyrillic symbols in tables in reportlab. hiroz 5 2,699 Sep-10-2020, 04:57 AM
Last Post: bradmalcom
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 497 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  How to create db table with SQLite and SQLAlchemy?? marcello86 1 508 Sep-02-2020, 03:05 PM
Last Post: marcello86
  Using Reportlab to create a landscape pdf SmukasPlays 2 504 Aug-09-2020, 09:31 PM
Last Post: SmukasPlays
  Create new column in new created table farhana88 1 390 Jun-09-2020, 07:20 AM
Last Post: buran
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 402 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  ReportLab Polypop77 0 345 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 855 Dec-26-2019, 05:57 AM
Last Post: buran
  Create table with psycopg2 on postgreSQL DB yhecohen 2 891 Aug-23-2019, 05:56 AM
Last Post: massimo_m
  Python Reportlab Wordwrap Table Mady 0 2,571 Dec-18-2018, 06:31 AM
Last Post: Mady

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020