daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Consultar Personal
  2.     personal_list = list(Personal.objects.all())
  3.  
  4.     # ESTABLECER BORDES
  5.     thin_border = Border(
  6.         left=Side(style='thin'), right=Side(style='thin'),
  7.         top=Side(style='thin'), bottom=Side(style='thin')
  8.     )
  9.  
  10.     # Creamos el libro de trabajo
  11.     wb = Workbook()
  12.  
  13.     # Definimos como nuestra hoja de trabajo, la hoja activa, por defecto la primera del libro
  14.     ws = wb.active
  15.     ws.title = "Nomina"
  16.     # En la celda B1 ponemos el texto 'REPORTE DE PERSONAS'
  17.     ws.merge_cells('B2:I2')
  18.     ws['B2'] = 'Listado en Nomina'
  19.     ws['B2'].alignment = Alignment(horizontal='center')
  20.     # ws.cell(row=2, column=2).border = thin_border
  21.     b2 = ws['B2']
  22.     b2.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  23.     # Creamos los encabezados desde la celda B3 hasta la E3
  24.     ws['B3'] = '#'
  25.     ws.cell(row=3, column=2).border = thin_border
  26.     ws.cell(row=3, column=2).alignment = Alignment(horizontal='center')
  27.     b3 = ws['B3']
  28.     b3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  29.  
  30.     ws['C3'] = 'Nombre'
  31.     ws.cell(row=3, column=3).border = thin_border
  32.     ws.cell(row=3, column=3).alignment = Alignment(horizontal='center')
  33.     c3 = ws['C3']
  34.     c3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  35.  
  36.     ws['D3'] = 'Cedula'
  37.     ws.cell(row=3, column=4).border = thin_border
  38.     ws.cell(row=3, column=4).alignment = Alignment(horizontal='center')
  39.     d3 = ws['D3']
  40.     d3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  41.  
  42.     ws['E3'] = 'Telefono'
  43.     ws.cell(row=3, column=5).border = thin_border
  44.     ws.cell(row=3, column=5).alignment = Alignment(horizontal='center')
  45.     e3 = ws['E3']
  46.     e3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  47.  
  48.     ws['F3'] = 'Celular'
  49.     ws.cell(row=3, column=6).border = thin_border
  50.     ws.cell(row=3, column=6).alignment = Alignment(horizontal='center')
  51.     f3 = ws['F3']
  52.     f3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  53.  
  54.     ws['G3'] = 'Correo'
  55.     ws.cell(row=3, column=7).border = thin_border
  56.     ws.cell(row=3, column=7).alignment = Alignment(horizontal='center')
  57.     g3 = ws['G3']
  58.     g3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  59.  
  60.     ws['H3'] = 'Cargo'
  61.     ws.cell(row=3, column=8).border = thin_border
  62.     ws.cell(row=3, column=8).alignment = Alignment(horizontal='center')
  63.     h3 = ws['H3']
  64.     h3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  65.  
  66.     ws['I3'] = 'Area'
  67.     ws.cell(row=3, column=9).border = thin_border
  68.     ws.cell(row=3, column=9).alignment = Alignment(horizontal='center')
  69.     i3 = ws['I3']
  70.     i3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  71.  
  72.     ws['J3'] = 'Fec. Ingreso'
  73.     ws.cell(row=3, column=10).border = thin_border
  74.     ws.cell(row=3, column=10).alignment = Alignment(horizontal='center')
  75.     j3 = ws['J3']
  76.     j3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  77.  
  78.     ws['K3'] = 'Fec. Salida'
  79.     ws.cell(row=3, column=11).border = thin_border
  80.     ws.cell(row=3, column=11).alignment = Alignment(horizontal='center')
  81.     k3 = ws['K3']
  82.     k3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  83.  
  84.     ws['L3'] = 'Tipo Sangre'
  85.     ws.cell(row=3, column=12).border = thin_border
  86.     ws.cell(row=3, column=12).alignment = Alignment(horizontal='center')
  87.     l3 = ws['L3']
  88.     l3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  89.  
  90.     ws['M3'] = 'Sueldo'
  91.     ws.cell(row=3, column=13).border = thin_border
  92.     ws.cell(row=3, column=13).alignment = Alignment(horizontal='center')
  93.     m3 = ws['M3']
  94.     m3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  95.  
  96.     ws['N3'] = 'Cargas'
  97.     ws.cell(row=3, column=14).border = thin_border
  98.     ws.cell(row=3, column=14).alignment = Alignment(horizontal='center')
  99.     n3 = ws['N3']
  100.     n3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  101.  
  102.     ws['O3'] = 'Nro. Cta.'
  103.     ws.cell(row=3, column=15).border = thin_border
  104.     ws.cell(row=3, column=15).alignment = Alignment(horizontal='center')
  105.     o3 = ws['O3']
  106.     o3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  107.  
  108.     ws['P3'] = 'Estado Civil'
  109.     ws.cell(row=3, column=16).border = thin_border
  110.     ws.cell(row=3, column=16).alignment = Alignment(horizontal='center')
  111.     p3 = ws['P3']
  112.     p3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  113.  
  114.     ws['Q3'] = 'Direccion'
  115.     ws.cell(row=3, column=17).border = thin_border
  116.     ws.cell(row=3, column=17).alignment = Alignment(horizontal='center')
  117.     q3 = ws['Q3']
  118.     q3.font = Font(bold=True, color=colors.DARKBLUE, size=12)
  119.  
  120.     cont = 4
  121.     indice = 1
  122.     for personal in personal_list:
  123.  
  124.         # agregamos la data, borde, alineacion
  125.         ws.cell(row=cont, column=2).value = indice
  126.         ws.cell(row=cont, column=2).border = thin_border
  127.         ws.cell(row=cont, column=2).alignment = Alignment(horizontal='center')
  128.  
  129.         # agregamos la data, borde, alineacion
  130.         ws.cell(row=cont, column=3).value = personal.nombre
  131.         ws.cell(row=cont, column=3).border = thin_border
  132.         ws.cell(row=cont, column=3).alignment = Alignment(horizontal='center')
  133.  
  134.         # agregamos la data, borde, alineacion
  135.         ws.cell(row=cont, column=4).value = personal.cedula
  136.         ws.cell(row=cont, column=4).border = thin_border
  137.         ws.cell(row=cont, column=4).alignment = Alignment(horizontal='center')
  138.  
  139.         # agregamos la data, borde, alineacion
  140.         if personal.telefono:
  141.             ws.cell(row=cont, column=5).value = personal.telefono
  142.         else:
  143.             ws.cell(row=cont, column=5).value = '---'
  144.         ws.cell(row=cont, column=5).border = thin_border
  145.         ws.cell(row=cont, column=5).alignment = Alignment(horizontal='center')
  146.  
  147.         # agregamos la data, borde, alineacion
  148.  
  149.         ws.cell(row=cont, column=6).value = personal.celular
  150.         ws.cell(row=cont, column=6).border = thin_border
  151.         ws.cell(row=cont, column=6).alignment = Alignment(horizontal='center')
  152.  
  153.         # agregamos la data, borde, alineacion
  154.         if personal.correo:
  155.             ws.cell(row=cont, column=7).value = personal.correo
  156.         else:
  157.             ws.cell(row=cont, column=7).value = '--'
  158.         ws.cell(row=cont, column=7).border = thin_border
  159.         ws.cell(row=cont, column=7).alignment = Alignment(horizontal='center')
  160.  
  161.         ws.cell(row=cont, column=8).value = personal.cargo.nombre
  162.         ws.cell(row=cont, column=8).border = thin_border
  163.         ws.cell(row=cont, column=8).alignment = Alignment(horizontal='center')
  164.  
  165.         ws.cell(row=cont, column=9).value = personal.area.nombre
  166.         ws.cell(row=cont, column=9).border = thin_border
  167.         ws.cell(row=cont, column=9).alignment = Alignment(horizontal='center')
  168.  
  169.         ws.cell(row=cont, column=10).value = personal.fec_ingreso
  170.         ws.cell(row=cont, column=10).border = thin_border
  171.         ws.cell(row=cont, column=10).alignment = Alignment(horizontal='center')
  172.  
  173.         ws.cell(row=cont, column=11).value = personal.fec_salida
  174.         ws.cell(row=cont, column=11).border = thin_border
  175.         ws.cell(row=cont, column=11).alignment = Alignment(horizontal='center')
  176.  
  177.         ws.cell(row=cont, column=12).value = personal.tipo_sangre
  178.         ws.cell(row=cont, column=12).border = thin_border
  179.         ws.cell(row=cont, column=12).alignment = Alignment(horizontal='center')
  180.  
  181.         ws.cell(row=cont, column=13).value = str(personal.sueldo)
  182.         ws.cell(row=cont, column=13).border = thin_border
  183.         ws.cell(row=cont, column=13).alignment = Alignment(horizontal='center')
  184.  
  185.         ws.cell(row=cont, column=14).value = personal.cargas_familiares
  186.         ws.cell(row=cont, column=14).border = thin_border
  187.         ws.cell(row=cont, column=14).alignment = Alignment(horizontal='center')
  188.  
  189.         ws.cell(row=cont, column=15).value = personal.cta_banco
  190.         ws.cell(row=cont, column=15).border = thin_border
  191.         ws.cell(row=cont, column=15).alignment = Alignment(horizontal='center')
  192.  
  193.         if personal.estado_civil == 1:
  194.             ws.cell(row=cont, column=16).value = 'Soltero(a)'
  195.         elif personal.estado_civil == 2:
  196.             ws.cell(row=cont, column=16).value = 'Casado(a)'
  197.         elif personal.estado_civil == 3:
  198.             ws.cell(row=cont, column=16).value = 'Divorciado(a)'
  199.         elif personal.estado_civil == 4:
  200.             ws.cell(row=cont, column=16).value = 'Viudo(a)'
  201.         ws.cell(row=cont, column=16).border = thin_border
  202.         ws.cell(row=cont, column=16).alignment = Alignment(horizontal='center')
  203.  
  204.         ws.cell(row=cont, column=17).value = personal.direccion
  205.         ws.cell(row=cont, column=17).border = thin_border
  206.         ws.cell(row=cont, column=17).alignment = Alignment(horizontal='center')
  207.  
  208.         cont = cont + 1
  209.         indice = indice + 1
  210.  
  211.     # Establecemos el nombre del archivo
  212.     nombre_archivo = "nomina.xlsx"
  213.  
  214.     # Definimos que el tipo de respuesta
  215.     response = HttpResponse(content_type="application/ms-excel")
  216.     contenido = "attachment; filename={0}".format(nombre_archivo)
  217.     response["Content-Disposition"] = contenido
  218.  
  219.     # ESTABLECER DIMENSIONES A COLUMNAS
  220.     ws.column_dimensions["A"].width = 10.0
  221.     ws.column_dimensions["C"].width = 40.0
  222.     ws.column_dimensions["D"].width = 20.0
  223.     ws.column_dimensions["E"].width = 20.0
  224.     ws.column_dimensions["F"].width = 20.0
  225.     ws.column_dimensions["G"].width = 40.0
  226.     ws.column_dimensions["H"].width = 20.0
  227.     ws.column_dimensions["I"].width = 20.0
  228.     ws.column_dimensions["J"].width = 20.0
  229.     ws.column_dimensions["K"].width = 20.0
  230.     ws.column_dimensions["L"].width = 20.0
  231.     ws.column_dimensions["M"].width = 20.0
  232.     ws.column_dimensions["N"].width = 10.0
  233.     ws.column_dimensions["O"].width = 20.0
  234.     ws.column_dimensions["P"].width = 20.0
  235.     ws.column_dimensions["Q"].width = 50.0
  236.  
  237.     wb.save(response)
  238.     # retorna el archivo excel
  239.     return response
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top