本文整理匯總了Python中reportlab.platypus.TableStyle.add方法的典型用法代碼示例。如果您正苦於以下問題:Python TableStyle.add方法的具體用法?Python TableStyle.add怎麽用?Python TableStyle.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reportlab.platypus.TableStyle
的用法示例。
在下文中一共展示了TableStyle.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: table
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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: print_entries
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例5: generate_monthly_summary_table
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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)
示例6: get_underline
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例7: gather_elements
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例8: getTableStyle
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例9: _new_style
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例10: getTableStyleThreeCol
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例11: print_inventory_surplus
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例12: print_inventory_existence
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
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
示例13: buildTable
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
def buildTable(data):
style = TableStyle()
style.add('VALIGN', (0,0), (-1,-1), 'TOP')
style.add('GRID', (0,0), (-1,-1), 1, colors.black)
style.add('ALIGN', (1,0), (1,-1), 'RIGHT')
table = Table(data, [width*0.2,width*0.4,width*0.4])
table.setStyle(style)
return table
示例14: _build_spectrum_table_style
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
def _build_spectrum_table_style(self):
tblstyle = TableStyle([
('SPAN', (0, 0), (-1, 0)),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, -1), 9),
('TEXTCOLOR', (0, 0), (-1, -1), colors.black),
('LINEBELOW', (0, 0), (-1, 0), 1, colors.black),
('LINEBELOW', (0, 1), (-1, 1), 1, colors.black),
# ('ALIGN', (2, 0), (2, 0), 'LEFT'),
('LINEBELOW', (0, 3), (-1, 3), 1.5, colors.black),
# ('LINEBELOW', (0, 0), (-1, -1), 1, colors.red),
# ('LINEBEFORE', (0, 0), (-1, -1), 1, colors.black),
('ALIGN', (2, 0), (-1, -1), 'CENTER')
])
for ir in self.int_plat_age_rowids:
tblstyle.add('SPAN', (1, ir), (3, ir))
tblstyle.add('SPAN', (1, ir + 1), (2, ir + 1))
for si in self.sample_rowids:
tblstyle.add('SPAN', (1, si), (-1, si))
return tblstyle
示例15: squareSection
# 需要導入模塊: from reportlab.platypus import TableStyle [as 別名]
# 或者: from reportlab.platypus.TableStyle import add [as 別名]
def squareSection(
page,
location,
size,
gridspace,
linefreq,
checkered,
rainbow,
gridline,
linewidth,
boxline,
checkeredcolor,
gridcolor,
linecolor,
boxcolor,
bgndcolor,
**excessParams
):
"""
Places a Cartesian graph in the specified location on the canvas.
Keyword arguments:
page -- a Canvas instance on which to draw
location -- location of the graph as a list of (x, y) tuple
size -- size of the graph as (width, height) tuple
gridspace -- size of individual grid cells
linefreq -- frequency of lines expressed as the number of rows per line
checkered -- true for checkered grid
rainbow -- true for rainbow grid
gridline -- thickness of lines around cells
linewidth -- width of each writing line
boxline -- thickness of border around graph(s), 0 for no box
checkeredcolor -- color of checkered boxes
gridcolor -- color of grid lines around cells
linecolor -- color of each line
boxcolor -- color of box surrounding graph(s)
bgndcolor -- color of background of each cell
"""
# dimensions and spacing
(area_w, area_h) = size
(loc_x, loc_y) = location
(cells_x, cells_y) = (int(area_w / gridspace), int(area_h / gridspace))
grid_w = cells_x * gridspace + boxline
grid_h = cells_y * gridspace + boxline
xMargins = (area_w - grid_w) / 2
yMargins = (area_h - grid_h) / 2
if cells_x < 1 or cells_y < 1:
raise ValueError('Specified dimensions do not fit on page.')
# create plain table
data = [['' for col in xrange(cells_x)] for row in xrange(cells_y)]
table = Table(data, colWidths=gridspace, rowHeights=gridspace)
# checkered grid or shaded background
pattern = list()
if checkered and rainbow:
raise ValueError('Grid pattern cannot be both rainbow and checekred.')
if checkered:
for y in xrange(cells_y):
for x in xrange(y % 2, cells_x, 2):
c = (x, y)
pattern.append(('BACKGROUND', c, c, grey(checkeredcolor)))
elif rainbow:
rainbow_pattern = rainbowGrid((cells_x, cells_y), darkness=5)
for x in xrange(cells_x):
for y in xrange(cells_y):
c = (x, y)
pattern.append(('BACKGROUND', c, c, rainbow_pattern[x][y]))
elif bgndcolor != 0:
pattern.append(('BACKGROUND', (0, 0), (-1, -1), grey(bgndcolor)))
# apply table style
style = TableStyle(pattern)
style.add('INNERGRID', (0, 0), (-1, -1), gridline, grey(gridcolor))
if boxline != 0:
style.add('BOX', (0, 0), (-1, -1), boxline, grey(boxcolor))
table.setStyle(style)
# writing lines
if linefreq != 0:
style = TableStyle()
for line in xrange(int(cells_y / linefreq) + 1):
rowline = line * linefreq
style.add('LINEABOVE', (0, rowline), (-1, rowline), linewidth,
grey(linecolor))
table.setStyle(style)
# draw graphs
#.........這裏部分代碼省略.........