本文整理汇总了Python中reportlab.platypus.Table.setStyle方法的典型用法代码示例。如果您正苦于以下问题:Python Table.setStyle方法的具体用法?Python Table.setStyle怎么用?Python Table.setStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.Table
的用法示例。
在下文中一共展示了Table.setStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_tabla_contenido
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def build_tabla_contenido(data):
"""
Construye la tabla del contenido del albaranSalida.
Los datos deben venir en listas. Cada línea de la tabla, una tupla o lista
con el código, descripción, cantidad, precio unitario (con dto. si lo
lleva e IVA) y número de pedido.
El precio y cantidad deben ser flotantes para poder calcular el subtotal.
"""
estilo_cabecera_tabla = ParagraphStyle("Cabecera tabla",
parent=estilos["Heading3"])
estilo_cabecera_tabla.fontName = "Times-Bold"
estilo_cabecera_tabla.alignment = enums.TA_CENTER
estilo_numeros_tabla = ParagraphStyle("Números tabla",
parent=estilos["Normal"])
estilo_numeros_tabla.alignment = enums.TA_RIGHT
datos = [(Paragraph(escribe("Código"), estilo_cabecera_tabla),
Paragraph(escribe("Descripción"), estilo_cabecera_tabla),
Paragraph("Cantidad", estilo_cabecera_tabla),
Paragraph("Precio/U", estilo_cabecera_tabla),
#Paragraph("Total c/IVA", estilo_cabecera_tabla),
# CWT: Prefiere la carta de portes sin IVA.
Paragraph("Total", estilo_cabecera_tabla),
Paragraph(escribe("Nº Pedido"), estilo_cabecera_tabla))
]
for d in data:
fila = (escribe(d[0]),
Paragraph(escribe(d[1]),estilos["Normal"]),
Paragraph(escribe(utils.float2str(d[2])),estilo_numeros_tabla),
Paragraph(escribe(utils.float2str(d[3])),estilo_numeros_tabla),
Paragraph(escribe(utils.float2str(d[2] * d[3])),
estilo_numeros_tabla),
escribe(d[4])
)
datos.append(fila)
tabla = Table(datos,
colWidths = (PAGE_WIDTH * 0.13,
PAGE_WIDTH * 0.35,
PAGE_WIDTH * 0.09,
PAGE_WIDTH * 0.09,
PAGE_WIDTH * 0.13,
PAGE_WIDTH * 0.11),
repeatRows = 1)
tabla.setStyle(TableStyle([
("BACKGROUND", (0, 0), (-1, 0), colors.lightgrey),
("LINEBEFORE", (0, 0), (-1, -1), 0.25, colors.black),
("LINEBELOW", (0, 0), (-1, 0), 1.0, colors.black),
("LINEBELOW", (0, "splitlast"), (-1, "splitlast"), 1.0, colors.black),
("BOX", (0, 0), (-1, -1), 1.0, colors.black),
("INNERGRID", (0, 0), (-1, -1), 0.25, colors.black),
("VALIGN", (0, 0), (-1, 0), "CENTER"),
("VALIGN", (0, 0), (0, -1), "TOP"),
("ALIGN", (0, 0), (-1, 0), "CENTER"),
("ALIGN", (-3, 1), (-1, -1), "RIGHT"),
#("ALIGN", (0, 1), (0, -1), "DECIMAL"), <- No puedo cambiar
# el pivotChar de "." a ",". No me vale.
("ALIGN", (-1, 1), (-1, -1), "CENTER"),
("ALIGN", (0, 1), (0, -1), "CENTER"),
#("RIGHTPADDING", (0, 1), (0, -1), 0.75 * cm),
]))
return tabla
示例2: draw_items
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def draw_items(self, invoice, canvas):
# Items
data = [[_('Quantity'), _('Description'), _('Amount'), _('Total')], ]
for item in invoice.items.all():
data.append([
item.quantity,
item.description,
format_currency(item.unit_price),
format_currency(item.total)
])
data.append(
[u'', u'', _('Total') + u":", format_currency(invoice.total)]
)
table = Table(data, colWidths=[1.7*cm, 11*cm, 2.5*cm, 2.5*cm])
table.setStyle([
('FONT', (0, 0), (-1, -1), self.FONT_NAME),
('FONTSIZE', (0, 0), (-1, -1), 10),
('TEXTCOLOR', (0, 0), (-1, -1), (0.2, 0.2, 0.2)),
('GRID', (0, 0), (-1, -2), 1, (0.7, 0.7, 0.7)),
('GRID', (-2, -1), (-1, -1), 1, (0.7, 0.7, 0.7)),
('ALIGN', (-2, 0), (-1, -1), 'RIGHT'),
('BACKGROUND', (0, 0), (-1, 0), (0.8, 0.8, 0.8)),
])
tw, th, = table.wrapOn(canvas, 15*cm, 19*cm)
table.drawOn(canvas, 1.5*cm, self.baseline-th)
self.baseline = -26*cm
示例3: _build_top
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def _build_top(self):
width = self.doc.width
invoice_date = self.invoice.get('invoice_date')
if self.payment and self.payment.status != 30:
title = "Avansa rēķins"
else:
title = "Rēķins"
im = None
if self.invoice.get('organiser_data').get('logo'):
adv = os.path.join(settings.MEDIA_ROOT, "adverts", self.invoice.get('organiser_data').get('logo'))
im = Image(adv, 100, 35)
# self.elements.append(im)
data = [[im if im else '', Paragraph(title, self.styles.get('h1')), 'Nr.', self.invoice.get('name')],
['', invoice_date, '', '']]
header_table = Table(data, colWidths=list((width / 4.0, width / 2.0, width / 16.0, (width * 3) / 16.0,), ))
header_table.setStyle(
TableStyle([
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('ALIGN', (3, 0), (3, 0), 'LEFT'),
('ALIGN', (2, 0), (2, 0), 'RIGHT'),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('BOX', (3, 0), (3, 0), 0.25, colors.darkgray),
('FONT', (0, 0), (-1, -1), 'Ubuntu'),
('SPAN', (0, 0), (0, 1)),
]))
self.elements.append(header_table)
示例4: generar_pdf
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def generar_pdf(request):
print ("Genero el PDF");
response = HttpResponse(content_type='application/pdf')
pdf_name = "proveedores.pdf" # llamado clientes
# la linea 26 es por si deseas descargar el pdf a tu computadora
# response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=40,
leftMargin=40,
topMargin=60,
bottomMargin=18,
)
proveedores = []
styles = getSampleStyleSheet()
header = Paragraph("Listado de Proveedores", styles['Heading1'])
proveedores.append(header)
headings = ('No. Proveedor','Nombre','RFC','Giro','Direccion','Ciudad','Estado','Pais','Telefono','Correo','Comentario')
allproveedores = [(p.num_proveedor, p.nombre, p.RFC ,p.giro ,p.direccion ,p.ciudad ,p.estado ,p.pais ,p.telefono ,p.correo ,p.comentario) for p in Proveedor.objects.all()]
print (allproveedores);
t = Table([headings] + allproveedores)
t.setStyle(TableStyle(
[
('GRID', (0, 0), (12, -1), 1, colors.dodgerblue),
('LINEBELOW', (0, 0), (-1, 0), 2, colors.darkblue),
('BACKGROUND', (0, 0), (-1, 0), colors.dodgerblue)
]
))
proveedores.append(t)
doc.build(proveedores)
response.write(buff.getvalue())
buff.close()
return response
示例5: generar_pdf_Producto
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def generar_pdf_Producto(request):
response = HttpResponse(content_type='application/pdf')
pdf_name = "productos.pdf"
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=40,
leftMargin=40,
topMargin=60,
bottomMargin=18,
)
productos = []
styles = getSampleStyleSheet()
header = Paragraph("Listado de Productos", styles['Heading1'])
productos.append(header)
headings = ('Proveedor','Nombre', 'Descripcion', 'Marca', 'Precio','Stock Actual')
allproductos = [(p.prov_id, p.pro_nom, p.pro_des, p.pro_mar, p.pro_pre, p.pro_sto_act) for p in Producto.objects.all()]
t = Table([headings] + allproductos)
t.setStyle(TableStyle(
[
('GRID', (0, 0), (6, -1), 1, colors.dodgerblue),
('LINEBELOW', (0, 0), (-1, 0), 2, colors.darkblue),
('BACKGROUND', (0, 0), (-1, 0), colors.dodgerblue)
]
))
productos.append(t)
doc.build(productos)
response.write(buff.getvalue())
buff.close()
return response
示例6: build_chart
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def build_chart(data, column, order, title):
"build chart"
headings = [('', _('Address'), _('Count'), _('Volume'), '')]
rows = [[draw_square(PIE_CHART_COLORS[index]),
tds_trunc(row[column], 45), row['num_count'],
filesizeformat(row['total_size']), '']
for index, row in enumerate(data)]
if len(rows) != 10:
missing = 10 - len(rows)
add_rows = [
('', '', '', '', '') for ind in range(missing)
]
rows.extend(add_rows)
headings.extend(rows)
dat = [row[order] for row in data]
total = sum(dat)
labels = [
("%.1f%%" % ((1.0 * row[order] / total) * 100))
for row in data
]
pie = PieChart()
pie.chart.labels = labels
pie.chart.data = dat
headings[1][4] = pie
table_with_style = Table(headings, [0.2 * inch,
2.8 * inch, 0.5 * inch, 0.7 * inch, 3.2 * inch])
table_with_style.setStyle(table_style)
paragraph = Paragraph(title, styles['Heading1'])
return [paragraph, table_with_style]
示例7: tradingReport
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def tradingReport(self, c):
title = "DAILY TRADING"
c.setFont("Helvetica", 24)
c.drawString(50,770, title)
c.setFont("Helvetica", 16)
c.drawString(50,730, "DATE :")
c.drawString(110,730, str(today.year) + "/" + str(today.month) + "/" + str(today.day) ) # DATE
c.line(110, 727, 185, 727)
c.drawString(300,730, "Today's Performance :")
c.line(465, 727, 515, 727)
c.drawString(470,730, "4%") # PROFIT value
c.drawString(50,680, "Market Analysis")
columHeight = [1*cm, 1*cm, 1*cm, 1*cm]
t=Table(self._data, 2.5*cm, columHeight) # The size of each cells
t.setStyle(TableStyle([('GRID',(0,0),(-1,-1),1,colors.black),
('VALIGN',(0,0),(-1,-1),'TOP')]))
t.wrapOn(c, 50,50)
t.drawOn(c, 50,550) #Table Location
c.drawString(50,500, "Intraday performance of Algorithm1")
graph_1 = Image("example.png")
graph_1.drawHeight = 6*cm
graph_1.drawWidth = 17.5*cm
#graph_1.wrapOn(c, 50,20)
graph_1.drawOn(c,50,322)
c.drawString(50,295, "Intraday performance of Algorithm2")
graph_2 = Image("example2.png")
graph_2.drawHeight = 6*cm
graph_2.drawWidth = 17.5*cm
#graph_2.wrapOn(c, 50,20)
graph_2.drawOn(c,50,117)
示例8: add_pdf_text
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def add_pdf_text(self, finding_name, phase, findings, risk_level, category_level, PoC_notes):
data = [
[Paragraph(finding_name, styles["Normal"]), Paragraph(phase, styles["Normal"])],
[Paragraph(findings, styles["Normal"]), Paragraph('Risk Level', styles["Normal"]), Paragraph('Category', styles["Normal"])],
[Paragraph('Proof of Concept', styles["Normal"]), Paragraph(risk_level, styles["Normal"]), Paragraph(category_level, styles["Normal"])],
[Paragraph(PoC_notes, styles["Normal"])],
[Paragraph('======================================================================================================================', styles["Normal"])],
]
table = Table(data, [3 * inch, 1.5 * inch, inch])
table_with_style = Table(data, [5 * inch, 1.5 * inch, inch])
table_with_style.setStyle(TableStyle([
('FONT', (0, 0), (-1, -1), 'Helvetica'),
('FONT', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONT', (0, 0), (-1, 1), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, -1), 8),
('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
('BOX', (0, 0), (-1, 0), 0.25, colors.green),
('ALIGN', (0, 0), (-1, 0), 'LEFT'),
]))
#~ parts.append(table)
Story = Spacer(1, 0.5 * inch)
parts.append(Story)
parts.append(table_with_style)
示例9: export_notes
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def export_notes(self, request, suffix=''):
""" Return an pdf export of user and public notes
Returns:
response
"""
res = Response()
student = self.__get_current_user()
try:
timecoded_data_set = self.__list_notes()
timecoded_data_array = []
for timecoded_data in timecoded_data_set:
timecoded_data_array.append([timecoded_data.seconds, Paragraph(timecoded_data.content.replace('\n','<br />'), ParagraphStyle("Page"))])
res.headerlist = [('Content-type', 'application/pdf'), ('Content-Disposition', 'attachment; filename=%s' % str(self.scope_ids.user_id)+".pdf")]
p = canvas.Canvas(res)
if (len(timecoded_data_array)>0):
table = Table(timecoded_data_array, colWidths=[20, 500])
table.setStyle(TableStyle([('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
('BOX', (0, 0), (-1, -1), 0.25, colors.black)]))
table.wrapOn(p, 700, 700)
table.drawOn(p, 50, 700)
p.showPage()
p.save()
return res
except KNoteList.DoesNotExist:
res.status = 404
return res
示例10: add_form
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def add_form(self, num_rows, form, is_mini_form=False):
cols = form.get_fields(print_only=True)
field_aliases, field_widths = ['ID'], [5]
field_aliases.extend([c.col_alias for c in cols])
field_widths.extend([c.display_width for c in cols])
field_widths = [n/100.0*self.inner_width for n in field_widths] #normalize
x, y = self.origin_x, self.origin_y + self.qr_size
width = self.inner_width
height = self.inner_height - self.qr_size - 35
if is_mini_form:
height = Units.pixel_to_point(300) #only render a 300-pixel tall form
data, rowheights, header_flowables = [], [39], []
style = ParagraphStyle(name='Helvetica', fontName='Helvetica', fontSize=10)
for a in field_aliases:
header_flowables.append(Paragraph('<b>%s</b>' % a, style))
data.append(header_flowables)
for n in range(0, num_rows):
data.append(['', '', '', ''])
rowheights.append(39)
t=Table(data, field_widths, rowheights)
GRID_STYLE = TableStyle([
('GRID', (0,0), (-1,-1), 0.25, colors.black),
('FONT', (0,0), (-1,-1), 'HandSean'),
('BOX',(0,0),(-1,-1),2,colors.black)
])
t.setStyle(GRID_STYLE)
frame = Frame(x, y, width, height, showBoundary=0, leftPadding=0,
bottomPadding=0, rightPadding=0, topPadding=0)
frame.addFromList([t], self.canvas)
示例11: add_form
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def add_form(self, num_rows, form, print_object):
cols = print_object.get_form_field_layout()
field_aliases, field_widths = ['ID'], [5]
field_aliases.extend([c.field.col_alias for c in cols])
field_widths.extend([c.width for c in cols])
field_widths = [n/100.0*self.inner_width for n in field_widths] #normalize
x, y = self.origin_x, self.origin_y + self.qr_size
width = self.inner_width
height = self.inner_height - self.qr_size - 35
data, rowheights, header_flowables = [], [39], []
style = ParagraphStyle(name='Helvetica', fontName='Helvetica', fontSize=10)
for a in field_aliases:
header_flowables.append(Paragraph('<b>%s</b>' % a, style))
data.append(header_flowables)
for n in range(0, num_rows):
data.append(['' for n in field_widths])
rowheights.append(39)
t=Table(data, field_widths, rowheights)
GRID_STYLE = TableStyle([
('GRID', (0,0), (-1,-1), 0.25, colors.black),
('FONT', (0,0), (-1,-1), 'HandSean'),
('BOX',(0,0),(-1,-1),2,colors.black)
])
t.setStyle(GRID_STYLE)
frame = Frame(x, y, width, height, showBoundary=0, leftPadding=0,
bottomPadding=0, rightPadding=0, topPadding=0)
frame.addFromList([t], self.canvas)
示例12: table
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [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]
示例13: cuadritos_en_ruta
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def cuadritos_en_ruta():
"""
Devuelve dos flowables:
Un texto centrado con el texto de "ENVASES VACÍOS..." y una tabla
con el texto y los cuadraditos que se rellenan a mano durante la ruta
del transportista.
"""
estilo_centrado = ParagraphStyle("Alineado centrado",
parent=estilos["Normal"])
estilo_centrado.alignment = enums.TA_CENTER
cab = Paragraph(escribe("ENVASES VACÍOS SIN LIMPIAR, 3 A.D.R."),
estilo_centrado)
datos = [["G.R.G. 1.000L", "", "", "BIDONES 100L", ""],
["", "", "", "", ""],
["DEPÓSITO 600L", "", "", "BIDONES 50L", ""],
["", "", "", "", ""],
["BIDONES 200L", "", "", "GARRAFAS 60L", ""],
["", "", "", "", ""],
["BIDONES 25L", "", "", "BIDONES 10L", ""]]
datos = [[escribe(c) for c in fila] for fila in datos]
tabla = Table(datos,
colWidths = (3*cm, 0.75*cm, 5*cm, 3*cm, 0.75*cm))
tabla.setStyle(TableStyle([
("BOX", (1, 0), (1, 0), 1.0, colors.black),
("BOX", (4, 0), (4, 0), 1.0, colors.black),
("BOX", (1, 2), (1, 2), 1.0, colors.black),
("BOX", (4, 2), (4, 2), 1.0, colors.black),
("BOX", (1, 4), (1, 4), 1.0, colors.black),
("BOX", (4, 4), (4, 4), 1.0, colors.black),
("BOX", (1, 6), (1, 6), 1.0, colors.black),
("BOX", (4, 6), (4, 6), 1.0, colors.black),
]))
return KeepTogether([Spacer(1, 0.3*cm), cab, Spacer(1, 0.5*cm), tabla])
示例14: build_marco_logo_y_empresa
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def build_marco_logo_y_empresa(dde):
"""
dde es una lista con la ruta al logotipo de la empresa (o None) y una
serie de líneas de texto con los datos a mostrar de la empresa.
Devuelve una tabla con los marcos transparentes con el logo y las
líneas.
"""
if dde[0] != None:
logo = Image(dde[0])
logo.drawHeight = 2*cm * logo.drawHeight / logo.drawWidth
logo.drawWidth = 2*cm
else:
logo = Paragraph("", estilos["Normal"])
lineas_empresa = dde[1:]
if len(lineas_empresa) <= 3:
empresa = Preformatted("\n".join(lineas_empresa), estilos["Normal"])
else:
texto_empresa = lineas_empresa[0] + "\n"
#+ ". ".join(lineas_empresa[1:])
resto_lineas = lineas_empresa[1:]
pivot = len(resto_lineas)/2
r1, r2 = resto_lineas[:pivot], resto_lineas[pivot:]
texto_empresa += ". ".join(r1) + "\n" + ". ".join(r2)
empresa = Preformatted(texto_empresa, estilos["Normal"])
datos = [[logo, empresa]]
tabla = Table(datos,
colWidths = (PAGE_WIDTH * 0.25,
PAGE_WIDTH * 0.65))
tabla.setStyle(TableStyle([
("ALIGN", (0, 0), (1, 0), "RIGHT"),
("ALIGN", (1, 0), (-1, -1), "LEFT"),
("VALIGN", (0, 0), (-1, -1), "CENTER"),
]))
return tabla
示例15: add_info
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import setStyle [as 别名]
def add_info(self):
ptext = "<b><font size=14>Report Info</font></b>"
self.Story.append(Paragraph(ptext, self.styles["BodyText"]))
self.Story.append(Spacer(1, 0.1 * inch))
data = [
["Request Name", self.request["custom_name"]],
["Request Id", str(self.request["_id"])],
["Email", self.request["email"]],
["Generated on", self.time_str()],
[
"Download Link",
'<a href="http://{0}/query/#/status/{1}">{0}/query/#/status/{1}</a>'.format(
self.download_server, self.request["_id"]
),
],
]
data = [[i[0], pg(i[1], 1)] for i in data]
t = Table(data)
t.setStyle(
TableStyle(
[("INNERGRID", (0, 0), (-1, -1), 0.25, colors.black), ("BOX", (0, 0), (-1, -1), 0.25, colors.black)]
)
)
self.Story.append(t)