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


Messages In This Thread
Help! - How to create a Title for a Reportlab Table - by crabbylou - Mar-29-2020, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with different sizes of columns in MS word pepe 8 1,412 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  [SOLVED] Looking for documentation on Reportlab's canvas.transform() function NeilUK 1 552 Aug-23-2023, 01:21 PM
Last Post: NeilUK
  Right to left alignment in python report using Reportlab jalal0034 1 1,761 Sep-27-2022, 04:25 AM
Last Post: jalal0034
  group by create pivot table python dawid294 1 1,257 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  Label Maker FPDF, Reportlab jamesaarr 1 2,601 Aug-09-2021, 11:57 PM
Last Post: Pedroski55
  cyrillic symbols in tables in reportlab. hiroz 5 11,190 Sep-10-2020, 04:57 AM
Last Post: bradmalcom
  How to create db table with SQLite and SQLAlchemy?? marcello86 1 2,270 Sep-02-2020, 03:05 PM
Last Post: marcello86
  Using Reportlab to create a landscape pdf SmukasPlays 2 5,280 Aug-09-2020, 09:31 PM
Last Post: SmukasPlays
  Create new column in new created table farhana88 1 1,781 Jun-09-2020, 07:20 AM
Last Post: buran
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 2,301 Apr-29-2020, 06:45 PM
Last Post: nisusavi

Forum Jump:

User Panel Messages

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