本文整理汇总了Python中reportlab.platypus.Table._argW[3]方法的典型用法代码示例。如果您正苦于以下问题:Python Table._argW[3]方法的具体用法?Python Table._argW[3]怎么用?Python Table._argW[3]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.platypus.Table
的用法示例。
在下文中一共展示了Table._argW[3]方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerarListaAsistencia
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def GenerarListaAsistencia (self,estudiantes,Curso, paralelo):
namefile = "ListaAsistencia_%s%s.pdf"%(Curso,paralelo)
doc = SimpleDocTemplate(namefile, pagesize=letter)
elements = []
styleSheet = getSampleStyleSheet()
titulo = Paragraph('''<b>Escuela Particular Dr. Jaime Aspiazu Seminario </b>''',styleSheet["BodyText"])
stringCurso = u"<b>Curso: %s año básico, Paralelo: %s</b>"%(Curso,paralelo)
subtitulo = Paragraph(stringCurso,styleSheet["BodyText"])
fecha = time.strftime("%d/%m/%y")
stringfecha = "Fecha: %s"%fecha
datosHeader = [[titulo],[subtitulo],[stringfecha],[]]
tablaHeader = Table(datosHeader)
tablaHeader.setStyle(TableStyle([ ('ALIGN',(0,0),(-1,-1),'CENTER'),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,0),(-1,-1),colors.black),
]))
#este es la etiqueta de la columna de enumeracion
N = Paragraph('''<b>N</b><super><font color=black>o</font></super>''', styleSheet["BodyText"])
datosEstudiante = [[N,u"Nómina Estudiantes", "1","2","3","4","5"]]
cont =1
for e in estudiantes:
aux = []
aux.append(str(cont))
aux.append(e)
aux.append(" ")
aux.append(" ")
aux.append(" ")
aux.append(" ")
aux.append(" ")
datosEstudiante.append(aux)
cont= cont + 1
tablaEstudiante = Table(datosEstudiante)
nFila = len(datosEstudiante)
tablaEstudiante.setStyle(TableStyle([ ('ALIGN',(0,0),(-1,-1),'LEFT'),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('TEXTCOLOR',(0,0),(-1,-1),colors.black),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
('BACKGROUND',(0,0),(0,nFila),colors.beige),
('BACKGROUND',(0,0),(6,0),colors.beige)
]))
tablaEstudiante._argW[0]=0.5*inch
tablaEstudiante._argW[1]=3*inch
tablaEstudiante._argW[2]=0.5*inch
tablaEstudiante._argW[3]=0.5*inch
tablaEstudiante._argW[4]=0.5*inch
tablaEstudiante._argW[5]=0.5*inch
tablaEstudiante._argW[6]=0.5*inch
elements.append(tablaHeader)
elements.append(tablaEstudiante)
doc.build(elements)
示例2: report4
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def report4(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
doc = SimpleDocTemplate(response, pagesize=letter)
# container for the 'Flowable' objects
elements = []
styleSheet = getSampleStyleSheet()
I = Image('replogo.jpeg')
I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth
I.drawWidth = 1.25*inch
P0 = Paragraph('''
<b>A pa<font color=red>r</font>a<i>graph</i></b>
<super><font color=yellow>1</font></super>''',
styleSheet["BodyText"])
P = Paragraph('''
<para align=center spaceb=3>The <b>ReportLab Left
<font color=red>Logo</font></b>
Image</para>''',
styleSheet["BodyText"])
data= [['A', 'B', 'C', P0, 'D'],
['00', '01', '02', [I,P], '04'],
['10', '11', '12', [P,I], '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green),
('BOX',(0,0),(1,-1),2,colors.red),
('LINEABOVE',(1,2),(-2,2),1,colors.blue),
('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
('BACKGROUND', (0, 0), (0, 1), colors.pink),
('BACKGROUND', (1, 1), (1, 2), colors.lavender),
('BACKGROUND', (2, 2), (2, 3), colors.orange),
('BOX',(0,0),(-1,-1),2,colors.black),
('GRID',(0,0),(-1,-1),0.5,colors.black),
('VALIGN',(3,0),(3,0),'BOTTOM'),
('BACKGROUND',(3,0),(3,0),colors.limegreen),
('BACKGROUND',(3,1),(3,1),colors.khaki),
('ALIGN',(3,1),(3,1),'CENTER'),
('BACKGROUND',(3,2),(3,2),colors.beige),
('ALIGN',(3,2),(3,2),'LEFT'),
])
t._argW[3]=1.5*inch
elements.append(t)
# write the document to disk
doc.build(elements)
return response
示例3: main
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def main():
doc = SimpleDocTemplate("json2pdf_example.pdf", pagesize=A4)
# container for the 'Flowable' objects
elements = []
styleSheet = getSampleStyleSheet()
I = Image('BMW.gif')
I.drawHeight = 1.25 * cm * I.drawHeight / I.drawWidth
I.drawWidth = 1.25 * cm
P0 = Paragraph('''
<b>A pa<font color=red>r</font>a<i>graph</i></b>
<super><font color=yellow>1</font></super>''',
styleSheet["BodyText"])
P = Paragraph('''
<para align=center spaceb=3>The <b>ReportLab Left
<font color=red>Logo</font></b>
Image</para>''',
styleSheet["BodyText"])
data = [['A', 'B', 'C', P0, 'D'],
['00', '01', '02', [I, P], '04'],
['10', '11', '12', [P, I], '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
style = [('GRID', (1, 1), (-2, -2), 1, colors.green),
('BOX', (0, 0), (1, -1), 2, colors.red),
('LINEABOVE', (1, 2), (-2, 2), 1, colors.blue),
('LINEBEFORE', (2, 1), (2, -2), 1, colors.pink),
('BACKGROUND', (0, 0), (0, 1), colors.pink),
('BACKGROUND', (1, 1), (1, 2), colors.lavender),
('BACKGROUND', (2, 2), (2, 3), colors.orange),
('BOX', (0, 0), (-1, -1), 2, colors.black),
('GRID', (0, 0), (-1, -1), 0.5, colors.black),
('VALIGN', (3, 0), (3, 0), 'BOTTOM'),
('BACKGROUND', (3, 0), (3, 0), colors.limegreen),
('BACKGROUND', (3, 1), (3, 1), colors.khaki),
('ALIGN', (3, 1), (3, 1), 'CENTER'),
('BACKGROUND', (3, 2), (3, 2), colors.beige),
('ALIGN', (3, 2), (3, 2), 'LEFT'),
]
style1 = [('BACKGROUND', (0, 0), (-1, 0), colors.Color(245, 215, 165))]
t = Table(data, style=style)
t._argW[3] = 1.5 * cm
elements.append(t)
# write the document to disk
doc.build(elements)
示例4: create_mag_kit
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def create_mag_kit():
global kitarray, namearry, filename2, sideframe, led, nametmp
names = ""
doc = SimpleDocTemplate(filename2, pagesize=letter)
# container for the 'Flowable' objects
elements = []
new = [(kitarray[0])]
styleSheet = getSampleStyleSheet()
if namearry[0] == "ALL":
names = "ALL"
for kit in kitarray:
if "A" in kit[6]:
new.append((kit))
else:
pass
else:
new = kitarray
for name in nametmp:
#print name
names += name+" | "
P = Paragraph('''<para align=center spaceb=3><b>'''+names+'''</b></para>''',styleSheet["BodyText"])
t=Table(new, style=[('GRID',(0,0),(-1,-1),1,colors.black)])
t._argW[3]=1.5*inch
elements.append(P)
elements.append(t)
# write the document to disk
doc.build(elements)
os.system("start "+filename2)
kitarray = []
namearry = []
led.set()
示例5: mydrawtable4
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def mydrawtable4():
szoveg0 = '''1'''
styleSheet = getSampleStyleSheet()
style1 = styleSheet['Normal']
story = []
P0 = Paragraph(szoveg0, style1)
P = Paragraph('''
<para align=center spaceb=3>The <b>ReportLab Left
<font color=red>Logo</font></b>
Image</para>''',
styleSheet['BodyText'])
data = [['A', 'B', 'C', P0, 'D'],
['00', '01', '02', P, '04'],
['10', '11', '12', P, '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
t = Table(data, style=[('GRID', (1, 1), (-2, -2), 1, colors.green),
('BOX', (0, 0), (1, -1), 2, colors.red),
('LINEABOVE', (1, 2), (-2, 2), 1, colors.blue),
('LINEBEFORE', (2, 1), (2, -2), 1, colors.pink),
('BACKGROUND', (0, 0), (0, 1), colors.pink),
('BACKGROUND', (1, 1), (1, 2), colors.lavender),
('BACKGROUND', (2, 2), (2, 3), colors.orange),
('BOX', (0, 0), (-1, -1), 2, colors.black),
('GRID', (0, 0), (-1, -1), 0.5, colors.black),
('VALIGN', (3, 0), (3, 0), 'BOTTOM'),
('BACKGROUND', (3, 0), (3, 0), colors.limegreen),
('BACKGROUND', (3, 1), (3, 1), colors.khaki),
('ALIGN', (3, 1), (3, 1), 'CENTER'),
('BACKGROUND', (3, 2), (3, 2), colors.beige),
('ALIGN', (3, 2), (3, 2), 'LEFT'),
])
t._argW[3] = 1.5 * inch
story.append(t)
doc = SimpleDocTemplate('mytables.pdf', pagesize=letter)
doc.build(story)
示例6: ImprimirVentasCreditos
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def ImprimirVentasCreditos(request, fechaI, fechaF):
response = HttpResponse(content_type='application/pdf')
finicio = datetime.fromtimestamp(int(fechaI) / 1e3)
ffin = datetime.fromtimestamp(int(fechaF) / 1e3)
pdf_name = "ventasacredito.pdf"
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=50,
leftMargin=50,
topMargin=20,
bottomMargin=18,
)
doc.pagesize = landscape(A4)
ventas = []
totales = Venta.objects.filter(fecha__gte = finicio, fecha__lte = ffin, credito = True , estado = 'ACTIVO').aggregate(precio_total=Sum(F('total')))
ventas.append(Spacer(1, 0.05 * inch))
header = Paragraph("GRUPOEJ - SRL." , getStyleSheet()['Title'])
subtitel = Paragraph("Ventas al credito." , getStyleSheet()['Subtitle'])
ventas.append(header)
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(subtitel)
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(Paragraph("<para>Fecha Inicio: "+finicio.strftime('%d/%m/%Y')+" "+" Fecha Fin:"+ffin.strftime('%d/%m/%Y')+"</para>", getStyleSheet()['TopicTitle8']))
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(Paragraph("DETALLE", getStyleSheet()['TopicTitle10']))
ventas.append(Spacer(1, 0.1 * inch))
styles = getSampleStyleSheet()
headings = ('DNI/RUC', 'CLIENTE', "RESPONSABLE", 'NRO_VENTA','FECHA' ,'TOTAL')
venta = [(str(v.pedido.cliente.nro_documento), str(v.pedido.cliente.nombres)+"/"+str(v.pedido.cliente.apellidos), str(v.pedido.cliente.responsable), str(v.numero_correlativo)+"-"+str(v.numero_documento), str(v.fecha), str(v.total)) for v in Venta.objects.filter(fecha__gte = finicio, fecha__lte = ffin, credito = True , estado = 'ACTIVO')]
data = ([headings] + venta)
data2 = [[Paragraph(cell, getStyleSheet()['TopicItemq0']) for cell in row] for row in data]
t=Table(data2)
style = TableStyle(
[
('BACKGROUND', (0, 0), (-1, 0), colors.gray),
('LINEABOVE', (0,0), (-1,0), 2, colors.green),
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
('ALIGN', (1,1), (-1,-1), 'CENTER'),
]
)
t.setStyle(style)
t._argW[0]=0.8*inch
t._argW[1]=2.8*inch
t._argW[2]=2.8*inch
t._argW[3]=0.9*inch
t._argW[4]=0.9*inch
t._argW[5]=0.9*inch
ventas.append(t)
ventas.append(Paragraph("Total: S/ "+str(totales['precio_total']), getStyleSheet()['TopicTitle8Right']))
# ventas.append(Paragraph("IGV:___"+str(venta.igv)+" S/", getStyleSheet()['TopicTitle8Right']))
# ventas.append(Paragraph("Total:__ "+str(venta.total)+" S/", getStyleSheet()['TopicTitle8Right']))
doc.build(ventas)
response.write(buff.getvalue())
buff.close()
return response
示例7: ImprimirVenta
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def ImprimirVenta(request, idventa):
response = HttpResponse(content_type='application/pdf')
pdf_name = "ventas.pdf"
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=50,
leftMargin=50,
topMargin=20,
bottomMargin=18,
)
doc.pagesize = landscape(A5)
ventas = []
venta = Venta.objects.get(id = idventa)
styles = getSampleStyleSheet()
header = Paragraph("GRUPOEJ - SRL." , getStyleSheet()['Title'])
documento = Paragraph("DOCUMENTO: "+(str(venta.tipo_documento))+" "+(str(venta.numero_correlativo))+"-"+(str(venta.numero_documento)) , getStyleSheet()['TopicItem1'])
cliente = Paragraph("CLIENTE / RAZON SOCIAL: "+(str(venta.pedido.cliente.nombres))+" "+(str(venta.pedido.cliente.apellidos))+" - "+(str(venta.pedido.cliente.area)) , getStyleSheet()['TopicItem1'])
ventas.append(header)
ventas.append(Spacer(1, 0.2 * inch))
ventas.append(documento)
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(cliente)
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(Paragraph(venta.pedido.cliente.tipo_documento+": "+venta.pedido.cliente.nro_documento+" ",getStyleSheet()['TopicItem1']))
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(Paragraph("DIRECCION: "+venta.pedido.cliente.direccion+" ",getStyleSheet()['TopicItem1']))
ventas.append(Spacer(1, 0.05 * inch))
ventas.append(Paragraph("FECHA DE COMPRA: "+datetime.strftime(venta.fecha, "%d-%m-%Y")+" ",getStyleSheet()['TopicItem1']))
ventas.append(Spacer(1, 0.1 * inch))
ventas.append(Paragraph("DETALLE DE LA COMPRA", getStyleSheet()['TopicTitle10']))
ventas.append(Spacer(1, 0.1 * inch))
headings = ('DESCRIPCION', 'PRECIO', "CANTIDAD", 'SUBTOTAL')
detalleventa = [(str(dv.producto.descripcion), str(dv.precio), str(dv.cantidad), str(dv.precio*dv.cantidad)) for dv in DetalleVenta.objects.filter(venta_id=idventa)]
data = ([headings] + detalleventa)
data2 = [[Paragraph(cell, getStyleSheet()['TopicItemq0']) for cell in row] for row in data]
t=Table(data2)
style = TableStyle(
[
('BACKGROUND', (0, 0), (-1, 0), colors.gray),
('LINEABOVE', (0,0), (-1,0), 2, colors.green),
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
('ALIGN', (1,1), (-1,-1), 'CENTER'),
]
)
t.setStyle(style)
t._argW[0]=4*inch
t._argW[1]=0.8*inch
t._argW[2]=0.8*inch
t._argW[3]=0.8*inch
ventas.append(t)
ventas.append(Paragraph("Sub total:__ "+str(venta.sub_total)+" S/", getStyleSheet()['TopicTitle8Right']))
ventas.append(Paragraph("IGV:___"+str(venta.igv)+" S/", getStyleSheet()['TopicTitle8Right']))
ventas.append(Paragraph("Total:__ "+str(venta.total)+" S/", getStyleSheet()['TopicTitle8Right']))
doc.build(ventas)
response.write(buff.getvalue())
buff.close()
return response
示例8: generate_case_report
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def generate_case_report(case, cs_docs):
cName = case[0]
cNumber = case[1]
cTitle = case[2]
cDescr = case[3]
cDate = case[4]
cLocation = case[5]
filename = cNumber + "_" + cName + "_report.pdf"
fileN = cNumber + "_" + cName + "_report"
# logo = os.path.join(os.path.dirname(os.path.abspath(__file__)),"static/reporting/images/crime_loud_logo.jpg")
response = HttpResponse(content_type="application/pdf")
response["Content-Disposition"] = "attachment; filename=" + filename
buffer = BytesIO()
# might have to change margins depending on what mamzo wants
my_pdf = SimpleDocTemplate(buffer, rightMarging=72, leftMargin=72, topMargin=15, bottomMargin=50)
# container for the pdf elements
elements = []
"""
f = Image(logo)
f.hAlign = 'CENTER'
f.drawHeight = 1.5*inch
f.drawWidth = 4 *inch
elements.append(f)
"""
styles = getSampleStyleSheet()
styleN = styles["Normal"]
styleH = styles["Heading1"]
styleH.alignment = TA_CENTER
elements.append(Paragraph("<h1>" + "Case Name: " + cName + "</h1>", styleH))
elements.append(Paragraph("<h3>" + "Case Number: " + cNumber + "</h3>", styleH))
elements.append(Paragraph("<h3>" + "Title: " + cTitle + "</h3>", styleH))
elements.append(Paragraph("<h3>" + "Description: " + cDescr + "</h3>", styleH))
elements.append(Paragraph("<h3>" + "Date: " + cDate + "</h3>", styleH))
elements.append(Paragraph("<h3>" + "Location: " + cLocation + "</h3>", styleH))
elements.append(Spacer(width=0, height=0.1 * cm))
##############################################
tdata = [[Paragraph("<b>" + "Crime Scene Uploads" + "</b>", styleN)]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(
TableStyle(
[
("GRID", (0, 0), (-1, 0), 1, colors.black),
("BACKGROUND", (0, 0), (-1, -1), colors.lightblue), # Give total a grey background)
]
)
)
table._argW[0] = 7.0 * inch
elements.append(table)
elements.append(Spacer(width=0, height=1 * cm))
tdata = [
[
Paragraph("<b>User Name</b>", styleN),
Paragraph("<b>Date</b>", styleN),
Paragraph("<b>Action</b>", styleN),
Paragraph("<b>Description</b>", styleN),
Paragraph("<b>PDE Date </b>", styleN),
]
]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([("GRID", (0, 0), (-1, -1), 1, colors.black)]))
table._argW[0] = 2.5 * inch # Set the size(width) of the first column in the table
table._argW[1] = 1.5 * inch
table._argW[2] = 1.5 * inch
table._argW[3] = 1.5 * inch
table._argW[4] = 1.5 * inch
elements.append(table)
elements.append(Spacer(width=0, height=1 * cm))
"""
this part of the table must loop through the community aray to display all available information
for example:
for k in cs_docs:
tdata = [k[0], k[1],k[2], k[3],k[4]]
table2 = Table(tdata, colWidths=None, rowHeights=None)
table2.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
#table=Table(tdata, colWidths=80, rowHeights=30)
table2._argW[0]=2.5*inch #Set the size(width) of the first collumn in the table
table2._argW[1]=1.5*inch
table2._argW[2]=1.5*inch
table2._argW[3]=1.5*inch
table2._argW[4]=1.5*inch
elements.append(table2)
elements.append(Spacer(width=0, height=1*cm))
"""
#.........这里部分代码省略.........
示例9:
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
Image</para>''',
styleSheet["BodyText"])
data= [['A', 'B', 'C', P0, 'D'],
['00', '01', '02', [I,P], '04'],
['10', '11', '12', [P,I], '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green),
('BOX',(0,0),(1,-1),2,colors.red),
('LINEABOVE',(1,2),(-2,2),1,colors.blue),
('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
('BACKGROUND', (0, 0), (0, 1), colors.pink),
('BACKGROUND', (1, 1), (1, 2), colors.lavender),
('BACKGROUND', (2, 2), (2, 3), colors.orange),
('BOX',(0,0),(-1,-1),2,colors.black),
('GRID',(0,0),(-1,-1),0.5,colors.black),
('VALIGN',(3,0),(3,0),'BOTTOM'),
('BACKGROUND',(3,0),(3,0),colors.limegreen),
('BACKGROUND',(3,1),(3,1),colors.khaki),
('ALIGN',(3,1),(3,1),'CENTER'),
('BACKGROUND',(3,2),(3,2),colors.beige),
('ALIGN',(3,2),(3,2),'LEFT'),
])
t._argW[3]=1.5*inch
elements.append(t)
# write the document to disk
doc.build(elements)
示例10: old_tables_test
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
#.........这里部分代码省略.........
from reportlab.lib.testutils import testsFolder
I = Image(os.path.join(os.path.dirname(testsFolder),'src','tools','pythonpoint','demos','leftlogo.gif'))
I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth
I.drawWidth = 1.25*inch
#I.drawWidth = 9.25*inch #uncomment to see better messaging
P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"])
B = TableBarChart()
BP = Paragraph("<para align=center spaceb=3>A bar chart in a cell.</para>", styleSheet["BodyText"])
data= [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'],
['00', '01', '02', [I,P], '04'],
['10', '11', '12', [I,P], '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34'],
['40', '41', '42', [B,BP], '44']]
t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green),
('BOX',(0,0),(1,-1),2,colors.red),
('LINEABOVE',(1,2),(-2,2),1,colors.blue),
('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
('BACKGROUND', (0, 0), (0, 1), colors.pink),
('BACKGROUND', (1, 1), (1, 2), colors.lavender),
('BACKGROUND', (2, 2), (2, 3), colors.orange),
('BOX',(0,0),(-1,-1),2,colors.black),
('GRID',(0,0),(-1,-1),0.5,colors.black),
('VALIGN',(3,0),(3,0),'BOTTOM'),
('BACKGROUND',(3,0),(3,0),colors.limegreen),
('BACKGROUND',(3,1),(3,1),colors.khaki),
('ALIGN',(3,1),(3,1),'CENTER'),
('BACKGROUND',(3,2),(3,2),colors.beige),
('ALIGN',(3,2),(3,2),'LEFT'),
])
t._argW[3]=1.5*inch
lst.append(t)
# now for an attempt at column spanning.
lst.append(PageBreak())
data= [['A', 'BBBBB', 'C', 'D', 'E'],
['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
sty = [
('ALIGN',(0,0),(-1,-1),'CENTER'),
('VALIGN',(0,0),(-1,-1),'TOP'),
('GRID',(0,0),(-1,-1),1,colors.green),
('BOX',(0,0),(-1,-1),2,colors.red),
#span 'BBBB' across middle 3 cells in top row
('SPAN',(1,0),(3,0)),
#now color the first cell in this range only,
#i.e. the one we want to have spanned. Hopefuly
#the range of 3 will come out khaki.
('BACKGROUND',(1,0),(1,0),colors.khaki),
('SPAN',(0,2),(-1,2)),
#span 'AAA'down entire left column
('SPAN',(0,0), (0, 1)),
('BACKGROUND',(0,0),(0,0),colors.cyan),
('LINEBELOW', (0,'splitlast'), (-1,'splitlast'), 1, colors.white,'butt'),
]
t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5)
lst.append(t)
示例11: generate_assessment_report
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def generate_assessment_report(assess_name, full_marks, module, data, freq, student_list, agg_name):
filename = assess_name + "_"+module+"_report.pdf"
fileN = assess_name + "_"+module+"_report"
logo = os.path.join(os.path.dirname(os.path.abspath(__file__)),"static/reporting/images/cs_header_image.jpg")
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename='+ filename
buffer = BytesIO()
my_pdf = SimpleDocTemplate(buffer, rightMarging=72, leftMargin=72, topMargin=15, bottomMargin=50)
#container for the pdf elements
elements = []
f = Image(logo)
f.hAlign = 'CENTER'
f.drawHeight = 1.5*inch
f.drawWidth = 4 *inch
elements.append(f)
styles=getSampleStyleSheet()
styleN = styles["Normal"]
styleH = styles["Heading1"]
styleH.alignment = TA_CENTER
elements.append(Paragraph('<h1>'+'Module: '+ module+'</h1>',styleH))
elements.append(Paragraph('<h3>'+'Assessment: '+ assess_name+'</h3>',styleH))
if agg_name is not None:
elements.append(Paragraph('<h3>'+'Aggregator: '+ agg_name+'</h3>',styleH))
else:
elements.append(Paragraph('<h3>'+'Aggregator: None '+ '</h3>',styleH))
elements.append(Paragraph('<h3>'+'Full Marks: '+ str(full_marks)+'</h3>',styleH))
elements.append(Spacer(width=0, height=0.1*cm))
tdata = [[Paragraph('<b>' + 'Statistics' + '</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,0),1, colors.black),
('BACKGROUND',(0,0),(-1,-1),colors.lightblue)#Give total a grey background)
]))
table._argW[0]=7.0*inch
elements.append(table)
elements.append(Spacer(width=0, height=1*cm))
tdata = [[Paragraph('<b>Class Average</b>',styleN),
Paragraph('<b>Median</b>',styleN),
Paragraph('<b>Mode</b>',styleN),
Paragraph('<b>Standard Deviation</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
table._argW[0]=2.5*inch #Set the size(width) of the first column in the table
table._argW[1]=1.5*inch
table._argW[2]=1.5*inch
table._argW[3]=1.5*inch
elements.append(table)
tdata = [data[0], data[1], data[2], data[3]],
table2 = Table(tdata, colWidths=None, rowHeights=None)
table2.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
#table=Table(tdata, colWidths=80, rowHeights=30)
table2._argW[0]=2.5*inch #Set the size(width) of the first collumn in the table
table2._argW[1]=1.5*inch
table2._argW[2]=1.5*inch
table2._argW[3]=1.5*inch
elements.append(table2)
elements.append(Spacer(width=0, height=1*cm))
tdata = [[Paragraph('<b>' + 'Frequency Analysis' + '</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,0),1, colors.black),
('BACKGROUND',(0,0),(-1,-1),colors.lightblue)#Give total a grey background)
]))
table._argW[0]=7.0*inch
elements.append(table)
elements.append(Spacer(width=0, height=1*cm))
tdata = [[Paragraph('<b>[0 .. 40)</b>',styleN),
Paragraph('<b>[40 .. 50)</b>',styleN),
Paragraph('<b>[50 .. 60)</b>',styleN),
Paragraph('<b>[60 .. 75)</b>',styleN),
Paragraph('<b>[75 .. 100]</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
table._argW[0]=1.4*inch #Set the size(width) of the first column in the table
table._argW[1]=1.4*inch
table._argW[2]=1.4*inch
table._argW[3]=1.4*inch
table._argW[4]=1.4*inch
elements.append(table)
tdata = [freq[0], freq[1], freq[2], freq[3], freq[4]],
#.........这里部分代码省略.........
示例12: generate_student_mark_pdf
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def generate_student_mark_pdf(data, student):
"""
Generates a PDF document with a student's marks,
then allowes for it to be downloaded by the student.
Arguments
Mraks : An associative array of marks for a student
module : The module the marks are for
"""
module = data[0]['assessment'][0]
filename = student + "_" + module + "_marks.pdf"
print "Location : " + str(os.path.abspath(__file__))
logo = os.path.join(os.path.dirname(os.path.abspath(__file__)),"static/reporting/images/cs_header_image.jpg")
#Extract student information to paint onto the document
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename='+ filename
buffer = BytesIO()
# Create the PDF object, using the BytesIO object as its "file."
c = canvas.Canvas(buffer)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
c.setFont("Times-Roman",14,leading=None)
c.drawString(30,750,"Student : " + student)
c.drawString(30,725,"Module : " + module)
#Add image on the top right of document
c.drawImage(logo, 400, 710, width=2.5*inch, height=1.0*inch)
c.line(180,710,380,710)
c.setFont("Helvetica-Bold", 12, leading=None)
styleN = styles['Normal']
#Get information on the assessment that was clicked
assessment_clicked = data[0]['assessment'][1][0]
assessment_clicked_obtained_mark = data[0]['assessment'][1][1]
assessment_clicked_total_mark = data[0]['assessment'][1][2]
assessment_clicked_percentage_obtained = '{0:.3}'.format(data[0]['assessment'][1][3])
#create row above the table specifying the assessment clicked
tdata = [[Paragraph('<b>' + assessment_clicked + '</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,0),1, colors.black)
]))
table._argW[0]=7.0*inch
table.wrapOn(c,100, 710)
table.drawOn(c,50, 600)
tdata = [[Paragraph('<b>Assessment</b>',styleN),
Paragraph('<b>Final Mark</b>',styleN),
Paragraph('<b>Mark obtained</b>',styleN),
Paragraph('<b>Percentage</b>',styleN)
]]
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
table._argW[0]=2.5*inch #Set the size(width) of the first collumn in the table
table._argW[1]=1.5*inch
table._argW[2]=1.5*inch
table._argW[3]=1.5*inch
#table=Table(tdata, colWidths=80, rowHeights=30)
table.wrapOn(c,100, 650)
table.drawOn(c,50,550)
currPos = 550
c.setFont("Helvetica", 11, leading=None)
#Create new table for the marks
tdata = []
for mark in data[0]['assessment'][2:]:
assessment_name = mark[0]
assessment_obtained_mark = mark[1]
assessment_total_mark = mark[2]
assessment_percentage_obtained = '{0:.3}'.format(mark[3])
tdata = [assessment_name, assessment_obtained_mark, assessment_total_mark, assessment_percentage_obtained],
table = Table(tdata, colWidths=None, rowHeights=None)
table.setStyle(TableStyle([
('GRID',(0,0), (-1,-1),1, colors.black)
]))
#table=Table(tdata, colWidths=80, rowHeights=30)
table._argW[0]=2.5*inch #Set the size(width) of the first collumn in the table
table._argW[1]=1.5*inch
table._argW[2]=1.5*inch
table._argW[3]=1.5*inch
table.wrapOn(c,75, 550)
currPos -= 20
table.drawOn(c,50, currPos)
#.........这里部分代码省略.........
示例13: ImprimirReporteEnvacePorProducto
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
def ImprimirReporteEnvacePorProducto(request, idcliente,idproducto):
response = HttpResponse(content_type='application/pdf')
pdf_name = "reporte_producto.pdf"
buff = BytesIO()
doc = SimpleDocTemplate(buff,
pagesize=letter,
rightMargin=50,
leftMargin=50,
topMargin=20,
bottomMargin=18,
)
# doc.pagesize = landscape(A4)
doc.pagesize = portrait(A4)
productos = []
cliente = Cliente.objects.get(id = idcliente)
# prod = Prestamo.objects.filter(id = idproducto)
# produc = Producto.objects.filter(id = prod[0].producto.id)
totales = Prestamo.objects.filter(cliente__id = idcliente, producto__id= idproducto).aggregate(
total_entregado=Sum(F('entregado'),output_field=FloatField()),
total_devuelto=Sum(F('devuelto'),output_field=FloatField())
)
# aggregate(total = Sum(F('cantidad')*F('precio'), output_field=FloatField())
# extra(select = {'total_entregado': 'SUM(entregado)','total_devuelto': 'SUM(devuelto)'})
styles = getSampleStyleSheet()
header = Paragraph("GRUPOEJ - SRL." , getStyleSheet()['Title'])
cli = Paragraph(str(cliente.nombres)+" "+str(cliente.apellidos)+" / "+str(cliente.area)+ " / "+ str(cliente.responsable), getStyleSheet()['TopicTitle8'])
productos.append(header)
productos.append(Spacer(1, 0.2 * inch))
productos.append(Paragraph("REPORTE TOTAL." , getStyleSheet()['TopicTitle14']))
productos.append(Spacer(1, 0.05 * inch))
productos.append(cli)
productos.append(Paragraph("DETALLE", getStyleSheet()['TopicTitle10']))
productos.append(Spacer(1, 0.1 * inch))
headings = ("PRODUCTO","FECHA","NRO DOCUMENTO","ENTREGADA ", 'DEVUELTA', 'DEBE')
detalleventa = [
(str(dv.producto.descripcion),str(dv.fecha),str(dv.nro_documento) ,str(dv.entregado), str(dv.devuelto), str(dv.entregado - dv.devuelto))
for dv in Prestamo.objects.filter(cliente__id = idcliente, producto__id= idproducto)]
data = ([headings] + detalleventa)
data2 = [[Paragraph(cell, getStyleSheet()['TopicItemq0']) for cell in row] for row in data]
t=Table(data2)
style = TableStyle(
[
('BACKGROUND', (0, 0), (-1, 0), colors.gray),
('LINEABOVE', (0,0), (-1,0), 2, colors.green),
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
('ALIGN', (1,1), (-1,-1), 'CENTER'),
]
)
t.setStyle(style)
t._argW[0]=2.5*inch
t._argW[1]=1.0*inch
t._argW[2]=1.2*inch
t._argW[3]=0.9*inch
t._argW[4]=0.8*inch
t._argW[5]=0.7*inch
productos.append(t)
productos.append(
Paragraph("Total Entregado "
+str(int(totales['total_entregado']))
+" "
+"Total Devuelto "
+str(int(totales['total_devuelto']))
+" "
+"TOTAL DEBE: "
+str(int(totales['total_entregado']) - int(totales['total_devuelto'])), getStyleSheet()['TopicTitle8Right']))
doc.build(productos)
response.write(buff.getvalue())
buff.close()
return response
示例14: imprimir
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
#.........这里部分代码省略.........
# elements.append(Paragraph("Deuda Inicial: $"+str(ficha.deuda_inicial), style))
# elements.append(Spacer(1, 0.2 * inch))
procurador = "Sin información"
if ficha.procurador:
procurador = ficha.procurador
deuda_inicial = 0
if ficha.deuda_inicial:
deuda_inicial = ficha.deuda_inicial
estado = "Sin informacion"
if ficha.estado:
estado = ficha.get_estado_display()
##elements.append(Paragraph("Procurador: "+ procurador, style))
##elements.append(Spacer(1, 0.2 * inch))
##elements.append(Paragraph("Estado: "+ficha.get_estado_display(), style))
##elements.append(Spacer(1, 0.2 * inch))
desc_style = ParagraphStyle(name="Normal", fontName="Helvetica", fontSize=9)
header = [["Nombre:", persona.nombres + " " + persona.apellidos, "Rut:", persona.get_rut()]]
header.append(["Dirección:", persona.domicilio, "", ""])
header.append(["Teléfono:", persona.telefono_fijo, "Celular:", persona.telefono_movil])
header.append(["Rol:", rol, "Carpeta:", carpeta])
header.append(["Tribunal:", tribunal, "Fecha Asignación:", ficha.fecha_creacion.strftime("%d/%m/%Y")])
header.append(["Deuda Inicial:", deuda_inicial, "Estado:", estado])
ts = [
("BOX", (0, 0), (-1, -1), 1, colors.grey),
("ALIGN", (1, 1), (-1, -1), "LEFT"),
("LINEABOVE", (0, 0), (-1, 0), 1, colors.black),
("FONT", (0, 0), (0, -1), "Helvetica-Bold"),
("FONT", (1, 0), (1, -1), "Helvetica"),
("FONT", (0, 0), (0, -1), "Helvetica-Bold"),
("FONT", (2, 0), (2, -1), "Helvetica-Bold"),
("FONT", (3, 0), (3, -1), "Helvetica"),
("SPAN", (1, 1), (-1, 1)),
]
head_table = Table(header, [1.2 * inch, 2.8 * inch, 1.8 * inch, 2.8 * inch])
head_table.setStyle(ts)
elements.append(head_table)
elements.append(Spacer(1, 0.2 * inch))
data = [["Fecha", "Código", "Descripción", "Receptor"]]
if eventos:
for evento in eventos:
codigo = ""
if evento.codigo.descripcion:
codigo = evento.codigo.descripcion
descripcion = ""
if evento.descripcion:
descripcion = evento.descripcion
receptor = ""
if evento.receptor:
receptor = evento.receptor
data.append(
[
Paragraph(evento.fecha.strftime("%d/%m/%Y"), desc_style),
Paragraph(codigo, desc_style),
Paragraph(descripcion, desc_style),
receptor,
]
)
ts2 = [
("BACKGROUND", (0, 0), (-1, 0), colors.grey),
# ('BOX',(0,0),(-1,-1),2,colors.grey),
("VALIGN", (0, 0), (-1, -1), "TOP"),
# ('ALIGN', (1,1), (-1,-1), 'LEFT'),
# ('LINEABOVE', (0,0), (0,-1), 1, colors.grey),
("FONT", (0, 1), (-1, -1), "Helvetica"),
("FONT", (0, 0), (-1, 0), "Helvetica-Bold"),
("ROWBACKGROUNDS", (0, 1), (-1, -1), ["#f7f7f7", "#f0f0f0"]),
]
# The bottom row has one line above, and three lines below of
# various colors and spacing.
# ('FONT', (0,-1), (-1,-1), 'Times-Bold')]
# Create the table with the necessary style, and add it to the
# elements list.
table = Table(data, style=ts2)
table._argW[0] = 0.8 * inch
table._argW[1] = 3 * inch
table._argW[2] = 4 * inch
table._argW[3] = 0.9 * inch
elements.append(table)
elements.append(Spacer(1, 0.2 * inch))
# Write the document to disk
doc.pagesize = landscape(LETTER)
doc.build(elements)
response.write(buffer.getvalue())
buffer.close()
return response
示例15: rpt_all_hours
# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import _argW[3] [as 别名]
#.........这里部分代码省略.........
tmps = datetime.datetime.strptime(h[0].horario.salida.strftime(format), format)
tmpe = datetime.datetime.strptime( h[0].horario.extraini.strftime(format), format )
iniex = tmps + datetime.timedelta(hours=tmpe.hour,minutes=tmpe.minute,seconds=tmpe.second)
almuerzo = 1
if x.salida > iniex.time():
# Horas extras
hs = datetime.datetime.strptime( x.salida.strftime(format), format )
hextras = hs - datetime.timedelta(hours=iniex.hour,minutes=iniex.minute,seconds=iniex.second)
thextra += datetime.timedelta(hours=hextras.hour,minutes=hextras.minute,seconds=hextras.second)
almuerzo = 1
sts = 'H. Extras'
else:
hs = datetime.datetime.strptime(h[0].horario.salida.strftime(format), format)
almuerzo = 1
sts = 'Completas'
else:
if days[day] == 'Sabado':
h = models.Horario.objects.filter(flag=True,tipo='CENTRAL',proyecto_id__isnull=True)[:1]
hs = h[0].satfin
almuerzo = 1
sts = 'DEFAULT'
else:
h = models.Horario.objects.filter(flag=True,tipo='CENTRAL',proyecto_id__isnull=True)[:1]
hs = h[0].salida
almuerzo = 1
sts = 'DEFAULT'
#Este caso es solo si la hora de salida no se ha registrato
#block salida sin data
# endblock salida sin data
hr = hs - datetime.timedelta(hours=he.hour,minutes=he.minute,seconds=he.second)
th = th + datetime.timedelta(hours=hr.hour,minutes=hr.minute,seconds=hr.second)
subt = hr - datetime.timedelta(hours=almuerzo,minutes=0)
hf += hr.hour
hf -= almuerzo
mf += hr.minute
sf += hr.second
hdf += dt.hour
mdf += dt.minute
sdf += dt.second
hxf += thextra.hour
mxf += thextra.minute
sxf += thextra.second
#print dt
#end block
else:
continue
#tbl.append([i,x.fecha,days[day],x.entrada,hs.strftime(format),hr.strftime(format),dt.strftime(format),datetime.time(almuerzo,0).strftime(format),hextras.strftime(format),subt.strftime(format),sts])
rango_year = int(request.GET['anio'])
rango_month = int(request.GET['mes'])
desde = datetime.date(1900,1,1)
hasta = datetime.date(1900,1,1)
if request.GET['periodo'] == '1':
# periodo value 1 primera, los primeros quince dias
desde = datetime.date(rango_year,rango_month,1)
hasta = datetime.date(rango_year,rango_month,15)
elif request.GET['periodo'] == '2':
import calendar
desde = datetime.date(rango_year,rango_month,16)
hasta = datetime.date(rango_year,rango_month,calendar.monthrange(rango_year,rango_month )[1] )
elif request.GET['periodo'] == '3':
import calendar
desde = datetime.date(rango_year,rango_month,1)
hasta = datetime.date(rango_year,rango_month,calendar.monthrange(rango_year,rango_month )[1] )
rht = returnsHours(hf,mf,sf)
rdt = returnsHours(hdf,mdf,sdf)
rxt = returnsHours(hxf,mxf,sxf)
completas = '%i:%s:%s'%(rht[0],"%02d"%rht[1],"%02d"%rht[2])
descuentos = '%i:%s:%s'%(rdt[0],"%02d"%rdt[1],"%02d"%rdt[2])
extras = '%i:%s:%s'%(rxt[0],"%02d"%rxt[1],"%02d"%rxt[2])
rango_periodo = "%s - %s"%(desde.strftime('%d/%m/%Y'),hasta.strftime('%d/%m/%Y'))
tbl.append([
i,nombre,rango_periodo,completas,descuentos,extras
])
i+=1
t = Table(tbl, style=[
('GRID',(0,0),(-1,-1),0.5,colors.black),
('BACKGROUND',(0,0),(-1,0),colors.limegreen),
('BACKGROUND',(1,1),(-1,-1),colors.beige),
('ALIGN',(0,0),(0,-1),'CENTER'),
('ALIGN',(0,0),(-1,0),'CENTER'),
])
t._argW[3]=1.5*inch
doc = SimpleDocTemplate(response,pagesize=landscape(LETTER),topMargin=10,bottomMargin=20)
styleSheet = getSampleStyleSheet()
elements.append( Paragraph('<font size=12>ICR PERU SA</font>', styleSheet['Normal']) )
h1 = styleSheet['Heading1']
h1.pageBreakBefore=0
h1.keepWithNext=1
P=Paragraph('Horario Periodo '+rango_periodo ,h1)
elements.append(P)
elements.append(t)
# write the document to disk
doc.build(elements)
return response
except Exception, e:
messages.error(request, 'No se ha podido cargar la pagina por precentar un error.')