本文整理匯總了Python中reportlab.platypus.TableStyle類的典型用法代碼示例。如果您正苦於以下問題:Python TableStyle類的具體用法?Python TableStyle怎麽用?Python TableStyle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TableStyle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: table
def table(data):
"""
return list, so "extend" method should be used.
"""
"""
para_style = STYLES["BodyText"]
para_style.wordWrap = 'CJK'
para_style.backColor = colors.red
table_data = [[Paragraph(cell, para_style) for cell in row] for row in data]
"""
table_data = data
table_style = TableStyle([
('ALIGN',(0,0),(-1,0),'CENTER'),
('ALIGN',(0,1),(0,-1),'LEFT'),
('ALIGN',(1,1),(-1,-1),'RIGHT'),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('BOX', (0,0), (-1,0), 2, colors.black),
('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
('TEXTCOLOR',(1,1),(-2,-2),colors.red),
('BACKGROUND', (0,0), (-1,0), colors.black),
('TEXTCOLOR',(0,0),(-1,0),colors.white),
('TEXTCOLOR',(0,1),(-1,-1),colors.black),
#('VALIGN',(0,0),(0,-1),'TOP'),
#('TEXTCOLOR',(0,0),(0,-1),colors.blue),
])
for i in range(1, len(table_data)):
if i%2 == 0:
table_style.add('BACKGROUND', (0,i), (-1,i),
colors.Color(.835,.91,.976))
t = Table(table_data)
t.setStyle(table_style)
return [t]
示例2: buildTable
def buildTable(data):
doc = SimpleDocTemplate("MOOSE_requirements_tracability.pdf", pagesize=A4, rightMargin=30,leftMargin=30, topMargin=30,bottomMargin=18)
doc.pagesize = landscape(A4)
elements = []
#Configure style and word wrap
s = getSampleStyleSheet()
s = s["BodyText"]
s.wordWrap = 'CJK'
pdf_data = [["Requirement", "Description", "Test Case(s)"]]
#TODO: Need a numerical sort here
keys = sorted(data.keys())
for key in keys:
data[key][2] = '\n'.join(data[key][2])
pdf_data.append([Paragraph(cell, s) for cell in data[key]])
# Build the Table and Style Information
tableThatSplitsOverPages = Table(pdf_data, 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),
('INNERGRID', (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,-1),colors.lightblue)
tblStyle.add('BACKGROUND',(0,1),(-1,-1),colors.white)
tableThatSplitsOverPages.setStyle(tblStyle)
elements.append(tableThatSplitsOverPages)
doc.build(elements)
示例3: make_table
def make_table(printable):
style = TableStyle()
style.add('VALIGN', (0,0), (-1,-1), 'TOP')
style.add('GRID', (0,0), (-1,-1), 1, colors.black)
table = Table(printable, [col_width*0.4,col_width*0.6])
table.setStyle(style)
return table
示例4: gather_elements
def gather_elements(self, client, node, style):
if node.children and isinstance(node.children[0], docutils.nodes.title):
title=[]
else:
title= [Paragraph(client.text_for_label(node.tagname, style),
style=client.styles['%s-heading'%node.tagname])]
rows=title + client.gather_elements(node, style=style)
st=client.styles[node.tagname]
if 'commands' in dir(st):
t_style = TableStyle(st.commands)
else:
t_style = TableStyle()
t_style.add("ROWBACKGROUNDS", [0, 0], [-1, -1],[st.backColor])
t_style.add("BOX", [ 0, 0 ], [ -1, -1 ], st.borderWidth , st.borderColor)
if client.splittables:
node.elements = [MySpacer(0,st.spaceBefore),
SplitTable([['',rows]],
style=t_style,
colWidths=[0,None],
padding=st.borderPadding),
MySpacer(0,st.spaceAfter)]
else:
padding, p1, p2, p3, p4=tablepadding(padding=st.borderPadding)
t_style.add(*p1)
t_style.add(*p2)
t_style.add(*p3)
t_style.add(*p4)
node.elements = [MySpacer(0,st.spaceBefore),
DelayedTable([['',rows]],
style=t_style,
colWidths=[0,None]),
MySpacer(0,st.spaceAfter)]
return node.elements
示例5: second_paragraph
def second_paragraph(self):
self.story.append(myParagraph(u"Nom du bénéficiaire : <b>" + self.facture_view.nom_prenom() + u"</b>", 'style1', spaceAfter=10))
self.story.append(myParagraph(u"Montant de la prestation", 'style1'))
self.story.append(myParagraph(u"<b>(" + self.facture_view.jours_prestation_string() + u")</b> Jours....................................<b>%.2f " % (self.facture_view.montant_presta()) + u"</b>€uros", 'style1', spaceAfter=25))
self.story.append(myParagraph(u"Arrêtée et certifiée conforme la présente facture à la somme de :", 'style1', spaceAfter=25))
table_style = TableStyle([('BOX', (0,0), (-1,-1), 0.25, black),
('BOX', (0,0), (-1,-1), 0.25, black),])
table_style.spaceAfter=25
table_data = [[myParagraph(u"<b>" + self.facture_view.montant_presta_word().upper() + u"</b>", 'style1', alignment=TA_CENTER),],]
self.story.append(Table(data=table_data, style=table_style))
示例6: print_entries
def print_entries(self, eh, ehds):
buffer = self.buffer
styles = getSampleStyleSheet()
data = []
ts = TableStyle()
d = []
hs = styles['Heading1']
hs.alignment = TA_CENTER
d.append(Paragraph('<b>Producto</b>', hs))
d.append(Paragraph('<b>Descripción</b>', hs))
d.append(Paragraph('<b>Cantidad</b>', hs))
if eh.printed:
if(eh.action == 'altas'):
title = Paragraph('<b> Entrada de Mercancía - REIMPRESIÓN</b>', hs)
else:
title = Paragraph('<b> Salida de Mercancía - REIMPRESIÓN</b>', hs)
else:
if(eh.action == 'altas'):
title = Paragraph('<b> Entrada de Mercancía </b>', hs)
else:
title = Paragraph('<b> Salida de Mercancía </b>', hs)
data.append(d)
total_qty = 0
sp = styles['BodyText']
sp.alignment = TA_CENTER
sq = styles['BodyText']
sq.alignment = TA_RIGHT
spb = styles['Heading3']
spb.alignment = TA_RIGHT
sl = styles['Normal']
sl.alignment = TA_CENTER
for ehd in ehds:
d = []
d.append(ehd.product.name)
p = Paragraph(ehd.product.description.encode('utf-8'), sp)
d.append(p)
pq = Paragraph(str(ehd.quantity), sq)
d.append(pq)
data.append(d)
total_qty += ehd.quantity
t = Table(data, colWidths = [(letter[0] * .20), (letter[0] * .50), (letter[0] * .20)])
ts.add('LINEBELOW', (0,1), (-1,-1), 0.25, colors.black)
t.setStyle(ts)
elements = []
elements.append(title)
elements.append(t)
elements.append(Paragraph('<br /><p> <b>Cantidad total de artículos:</b> ' + str(total_qty) + '</p>', spb))
if(eh.action == 'altas'):
elements.append(Paragraph('<br /><p> Al firmar este documento acepto que estoy recibiendo la mercancía listada y me responsabilizo por la mercancía. <br /><br /><br/> Nombre:_____________________ Firma: _____________________________</p>',sl))
else:
elements.append(Paragraph('<br /><p> Al firmar este documento acepto la salida de esta mercancía. <br /><br /><br/> Nombre:_____________________ Firma: _____________________________</p>',sl))
doc = SimpleDocTemplate(buffer, pagesize=letter)
doc.build(elements, onFirstPage=self._header_footer, onLaterPages=self._header_footer, canvasmaker = NumberedCanvas)
return buffer
示例7: generate_monthly_summary_table
def generate_monthly_summary_table(huc12):
"""Make a table of monthly summary stats."""
data = []
data.append(['Year', 'Month', 'Precip', "Runoff", "Loss", "Delivery",
'2+" Precip', 'Events'])
data.append(['', '', '[inch]', "[inch]", "[tons/acre]", "[tons/acre]",
"[days]", "[days]"])
pgconn = get_dbconn('idep')
huc12col = "huc_12"
if len(huc12) == 8:
huc12col = "substr(huc_12, 1, 8)"
df = read_sql("""
WITH data as (
SELECT extract(year from valid)::int as year,
extract(month from valid)::int as month, huc_12,
(sum(qc_precip) / 25.4)::numeric as sum_qc_precip,
(sum(avg_runoff) / 25.4)::numeric as sum_avg_runoff,
(sum(avg_loss) * 4.463)::numeric as sum_avg_loss,
(sum(avg_delivery) * 4.463)::numeric as sum_avg_delivery,
sum(case when qc_precip >= 50.8 then 1 else 0 end) as pdays,
sum(case when avg_loss > 0 then 1 else 0 end) as events
from results_by_huc12 WHERE scenario = 0 and
""" + huc12col + """ = %s
and valid >= '2016-01-01'
GROUP by year, month, huc_12)
SELECT year, month,
round(avg(sum_qc_precip), 2),
round(avg(sum_avg_runoff), 2),
round(avg(sum_avg_loss), 2),
round(avg(sum_avg_delivery), 2),
round(avg(pdays)::numeric, 1),
round(avg(events)::numeric, 1)
from data GROUP by year, month ORDER by year, month
""", pgconn, params=(huc12, ), index_col=None)
for _, row in df.iterrows():
vals = [int(row['year']), calendar.month_abbr[int(row['month'])]]
vals.extend(["%.2f" % (f, ) for f in list(row)[2:-2]])
vals.extend(["%.0f" % (f, ) for f in list(row)[-2:]])
data.append(vals)
data[-1][1] = "%s*" % (data[-1][1], )
totals = df.iloc[:-1].mean()
vals = ['', 'Average']
vals.extend(["%.2f" % (f, ) for f in list(totals[2:])])
data.append(vals)
style = TableStyle(
[('LINEBELOW', (2, 1), (-1, 1), 0.5, '#000000'),
('LINEAFTER', (1, 2), (1, -2), 0.5, '#000000'),
('LINEABOVE', (2, -1), (-1, -1), 0.5, '#000000'),
('ALIGN', (0, 0), (-1, -1), 'RIGHT')]
)
for rownum in range(3, len(data)+1, 2):
style.add('LINEBELOW', (0, rownum), (-1, rownum), 0.25, '#EEEEEE')
return Table(data, style=style, repeatRows=2)
示例8: frein_type_result
def frein_type_result(self, frein_type, resultat_list):
en_tete = ((StatParagraph("<b><i>" + frein_type + "</i></b>", 'style3'),
StatParagraph("<b><i>" + u"Frein le plus important" + "</i></b>", 'style3'),
StatParagraph("<b><i>" + u"Frein présent" + "</i></b>", 'style3')),)
data = tuple([(StatParagraph(categorie, 'style3'),
StatParagraph(str(nb_plus_imp), 'style3'),
StatParagraph(str(nb_all), 'style3'))
for (categorie, nb_plus_imp, nb_all) in resultat_list])
table_data = en_tete + data
table_style = TableStyle([('GRID', (0,0), (-1,-1), 0.25, black),])
table_style.spaceAfter=25
table_style.spaceBefore=25
self.story.append(Table(data=table_data, style=table_style))
示例9: get_underline
def get_underline():
data = [[None], [None]]
line = Table(
data,
colWidths=[6.2 * inch],
rowHeights=[0.03 * inch, 0.14 * inch])
table_style = TableStyle()
table_style.add('LINEBELOW', (0, 0), (0, 0), 1, colors.black)
line.setStyle(table_style)
return line
示例10: getTableStyle
def getTableStyle():
ts = TableStyle([('TEXTCOLOR', (0, 0), (-1, -1), colors.black),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
('LINEBELOW', (0, 0), (-1, -1), 0.8, colors.black),
('BOX', (0, 0), (-1, -1), 0.75, colors.black),
('BOX', (0, 0), (0, -1), 0.75, colors.black),
('BOX', (1, 0), (1, -1), 0.75, colors.black),
('ALIGN', (0, 0), (-1, -1), 'RIGHT'),
('FONTNAME', (0, 0), (-1, -1), 'Arabic'),
('FONTSIZE', (0, 0), (-1, -1), TABLE_FONT_SIZE),
])
ts.add('BACKGROUND', (0, 0), (-1, 1), colors.lightgrey) # header lightgrey
ts.add('BACKGROUND', (0, 1), (-1, -1), colors.white) # rest of table
return ts
示例11: _new_style
def _new_style(self, header_line_idx=None, header_line_width=1, header_line_color="black", debug_grid=False):
ts = TableStyle()
if debug_grid:
ts.add("GRID", (0, 0), (-1, -1), 1, colors.red)
if isinstance(header_line_color, str):
try:
header_line_color = getattr(colors, header_line_color)
except AttributeError:
header_line_color = colors.black
if header_line_idx is not None:
ts.add("LINEBELOW", (0, header_line_idx), (-1, header_line_idx), header_line_width, header_line_color)
return ts
示例12: getTableStyleThreeCol
def getTableStyleThreeCol():
ts = TableStyle([('TEXTCOLOR', (0, 0), (-1, -1), colors.black),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
('LINEBELOW', (0, 0), (-1, -1), 0.8, colors.black),
('BOX', (0, 0), (-1, -1), 0.75, colors.black),
('BOX', (0, 0), (0, -1), 0.75, colors.black),
('BOX', (1, 0), (1, -1), 0.75, colors.black),
('ALIGN', (0, 0), (0, -1), 'CENTER'), # center number column
('ALIGN', (1, 0), (1, -1), 'RIGHT'), # right align name column
('ALIGN', (2, 0), (2, -1), 'CENTER'), # center number column
('FONTNAME', (0, 0), (-1, -1), 'Arabic'),
('FONTSIZE', (0, 0), (-1, -1), TABLE_FONT_SIZE),
])
ts.add('BACKGROUND', (0, 0), (-1, 1), colors.lightgrey) # header lightgrey
ts.add('BACKGROUND', (0, 1), (-1, -1), colors.white) # rest of table
return ts
示例13: tableau_intro
def tableau_intro(self):
style_tableau = TableStyle([('BOX', (0,0), (0,-1), 0.25, black),
('BOX', (1,0), (1,-1), 0.25, black),
('BOX', (2,0), (2,-1), 0.25, black),
('BOX', (0,0), (-1,0), 0.25, black),
('VALIGN',(0,0),(-1,-1),'TOP'),
])
style_tableau.spaceAfter = 10
tableau_data = [[MyParagraph(style='style3', text=u"<b>Bénéficiaire</b>"), MyParagraph(style='style3', text=u"<b>Référent</b>"), MyParagraph(style='style3', text=u"<b>Correspondant ALE</b>")],
[MyParagraph(style='style3', text=u"<b>Nom Prénom : <font color=black>"+self.bilanView.nomprenom()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Nom Prénom : <font color=black>"+self.bilanView.CInomprenom()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Nom Prénom : <font color=black>"+self.bilanView.ALEnomprenom()+"</font></b>")],
[MyParagraph(style='style3', text=u"<b>Identifiant n° : <font color=black>"+self.bilanView.idALE()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Organisme : <font color=black>"+self.bilanView.organismeReferent()+"</font></b>"), MyParagraph(style='style3', text=u"<b>ALE : <font color=black>"+self.bilanView.ALEnom()+"</font></b>")],
[MyParagraph(style='style3', text=u"<b>Inscrit à ALE de: <font color=black>"+self.bilanView.incritALE()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Tél : <font color=black>"+self.bilanView.refTel()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Tél : <font color=black>"+self.bilanView.ALEtel()+"</font></b>")],
[MyParagraph(style='style3', text=u"<b>Tél : <font color=black>"+self.bilanView.LCtel()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Mel : <font color=black>"+self.bilanView.refMail()+"</font></b>"), MyParagraph(style='style3', text=u"<b>Mel : <font color=black>"+self.bilanView.ALEmail()+"</font></b>")],
[MyParagraph(style='style3', text=u"<b>Mel : <font color=black>"+self.bilanView.LCmail()+"</font></b>"), None, None],
]
tableau = Table(data=tableau_data, style=style_tableau)
self.story.append(tableau)
示例14: print_inventory_surplus
def print_inventory_surplus(self, entries, title):
buffer = self.buffer
styles = getSampleStyleSheet()
data = []
ts = TableStyle()
d = []
hs = styles['Heading1']
hs.alignment = TA_CENTER
d.append(Paragraph('<b>Código</b>', styles['Normal']))
d.append(Paragraph('<b>Descripción</b>', styles['Normal']))
d.append(Paragraph('<b>Existencia</b>', styles['Normal']))
d.append(Paragraph('<b>Sistema</b>', styles['Normal']))
d.append(Paragraph('<b>Sobrante</b>', styles['Normal']))
title = Paragraph('<b> ' + title + '</b>', hs)
data.append(d)
total_qty = 0
sp = styles['BodyText']
sp.alignment = TA_CENTER
sq = styles['BodyText']
sq.alignment = TA_RIGHT
spb = styles['Heading3']
spb.alignment = TA_RIGHT
sl = styles['Normal']
sl.alignment = TA_CENTER
for e in entries:
if e['entry'].product is None:
continue
d = []
d.append(e['entry'].product.name)
p = Paragraph(e['entry'].product.description.encode('utf-8'), sp)
d.append(p)
pq = Paragraph(str(e['entry'].quantity), sq)
d.append(pq)
d.append(Paragraph(str(e['tcount']), sq))
d.append(Paragraph(str(e['diff'] * -1), sq))
data.append(d)
t = Table(data, colWidths = [(letter[0] * .15), (letter[0] * .45), (letter[0] * .12), (letter[0] * .12), (letter[0] * .12)])
ts.add('LINEBELOW', (0,1), (-1, -1), 0.25, colors.black)
t.setStyle(ts)
elements = []
elements.append(title)
elements.append(t)
doc = SimpleDocTemplate(buffer, pagesize=letter)
doc.build(elements, onFirstPage=self._header_footer_inventory, onLaterPages=self._header_footer_inventory, canvasmaker = NumberedCanvas)
return buffer
示例15: print_inventory_existence
def print_inventory_existence(self, entries, title):
buffer = self.buffer
styles = getSampleStyleSheet()
data = []
ts = TableStyle()
d = []
hs = styles['Heading1']
hsc = styles['Heading3']
hs.alignment = TA_CENTER
d.append(Paragraph('<b>Código</b>', styles['Normal']))
d.append(Paragraph('<b>Descripción</b>', styles['Normal']))
d.append(Paragraph('<b>Cantidad</b>', styles['Normal']))
title = Paragraph('<b> ' + title + '</b>', styles['Normal'])
data.append(d)
total_qty = 0
sp = styles['BodyText']
sp.alignment = TA_CENTER
sq = styles['BodyText']
sq.alignment = TA_RIGHT
spb = styles['Heading3']
spb.alignment = TA_RIGHT
sl = styles['Normal']
sl.alignment = TA_CENTER
for e in entries:
if e.quantity == 0:
continue
d = []
d.append(e.product.name)
p = Paragraph(e.product.description.encode('utf-8'), sp)
d.append(p)
pq = Paragraph(str(e.quantity), sq)
d.append(pq)
data.append(d)
total_qty += e.quantity
t = Table(data, colWidths = [(letter[0] * .20), (letter[0] * .50), (letter[0] * .20)])
ts.add('LINEBELOW', (0,1), (-1, -1), 0.25, colors.black)
t.setStyle(ts)
elements = []
elements.append(title)
elements.append(t)
elements.append(Paragraph('<br /><p> <b>Cantidad total de artículos:</b> ' + str(total_qty) + '</p>', spb))
doc = SimpleDocTemplate(buffer, pagesize=letter)
doc.build(elements, onFirstPage=self._header_footer_inventory, onLaterPages=self._header_footer_inventory, canvasmaker = NumberedCanvas)
return buffer