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
  [SOLVED] Reportlab - change a single page orientation beetlecad 1 1,523 Aug-16-2024, 05:43 PM
Last Post: beetlecad
  Highlight text with Reportlab beetlecad 2 1,959 Aug-07-2024, 09:36 AM
Last Post: Pedroski55
  How to create a table with different sizes of columns in MS word pepe 8 7,904 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  [SOLVED] Looking for documentation on Reportlab's canvas.transform() function NeilUK 1 1,486 Aug-23-2023, 01:21 PM
Last Post: NeilUK
  Right to left alignment in python report using Reportlab jalal0034 1 3,708 Sep-27-2022, 04:25 AM
Last Post: jalal0034
  group by create pivot table python dawid294 1 2,118 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  Label Maker FPDF, Reportlab jamesaarr 1 4,234 Aug-09-2021, 11:57 PM
Last Post: Pedroski55
  cyrillic symbols in tables in reportlab. hiroz 5 15,394 Sep-10-2020, 04:57 AM
Last Post: bradmalcom
  How to create db table with SQLite and SQLAlchemy?? marcello86 1 2,904 Sep-02-2020, 03:05 PM
Last Post: marcello86
  Using Reportlab to create a landscape pdf SmukasPlays 2 8,494 Aug-09-2020, 09:31 PM
Last Post: SmukasPlays

Forum Jump:

User Panel Messages

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