private void GenerarExcel() { NecesidadesCapacitacionNegocio neg = new NecesidadesCapacitacionNegocio(); string prioridades = null; if (lstDepartamento.Items[0].Value != "") { vIdDepartamento = int.Parse(lstDepartamento.Items[0].Value); vNbDepartamento = lstDepartamento.Items[0].Text; } else { vIdDepartamento = null; } xmlPrioridades = new XElement("PRIORIDADES"); if (chkAlta.Checked) { xmlPrioridades.Add(new XElement("PRIORIDAD", new XAttribute("NOMBRE", "Alta"))); } if (chkIntermedia.Checked) { xmlPrioridades.Add(new XElement("PRIORIDAD", new XAttribute("NOMBRE", "Intermedia"))); } if (chkNoNecesaria.Checked) { xmlPrioridades.Add(new XElement("PRIORIDAD", new XAttribute("NOMBRE", "No Necesaria"))); } if (xmlPrioridades.HasElements) { prioridades = xmlPrioridades.ToString(); } UDTT_ARCHIVO excel = neg.ExportarDatosExcel(vIdPeriodo, vIdDepartamento, vNbDepartamento, prioridades, null); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excel.NB_ARCHIVO); Response.BinaryWrite(excel.FI_ARCHIVO); Response.Flush(); Response.End(); }
private void GenerarExcel() { EventoCapacitacionNegocio neg = new EventoCapacitacionNegocio(); UDTT_ARCHIVO excel = neg.ListaAsistencia(vIdEventoSeleccionado, vIdRol); if (excel.FI_ARCHIVO.Length != 0) { Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excel.NB_ARCHIVO); Response.BinaryWrite(excel.FI_ARCHIVO); Response.Flush(); Response.End(); } else { UtilMensajes.MensajeResultadoDB(rwmAlertas, "No hay participantes en este evento", E_TIPO_RESPUESTA_DB.WARNING, 400, 150, null); } }
private void GenerarExcelDetallada() { ConsultaPersonalNegocio neg = new ConsultaPersonalNegocio(); UDTT_ARCHIVO excel = neg.obtieneConsultaPersonalDetalladaExcel(vIdBateria, txtCandidato.InnerText, txtFolio.InnerText); if (excel.FI_ARCHIVO.Length != 0) { Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excel.NB_ARCHIVO); Response.BinaryWrite(excel.FI_ARCHIVO); Response.Flush(); Response.End(); } else { UtilMensajes.MensajeResultadoDB(rwmAlertas, "No hay datos para exportar.", E_TIPO_RESPUESTA_DB.WARNING, 400, 150, null); } }
public UDTT_ARCHIVO obtieneConsultaPersonalDetalladaExcel(int pIdBateria, string pNbCandidato, string pClFolio) { UDTT_ARCHIVO oConsultaPersonal = new UDTT_ARCHIVO(); Stream newStream = new MemoryStream(); Utilerias.Utilerias aux = new Utilerias.Utilerias(); ConsultaPersonalOperaciones op = new ConsultaPersonalOperaciones(); List <SPE_OBTIENE_CONSULTA_PERSONAL_DETALLADA_Result> vListaDetallada = new List <SPE_OBTIENE_CONSULTA_PERSONAL_DETALLADA_Result>(); List <SPE_OBTIENE_FACTORES_CONSULTA_Result> vListaFactores = new List <SPE_OBTIENE_FACTORES_CONSULTA_Result>(); List <SPE_OBTIENE_COMPETENCIAS_CONSULTA_Result> vListaCompetencias = new List <SPE_OBTIENE_COMPETENCIAS_CONSULTA_Result>(); List <SPE_OBTIENE_FACTORES_COMPETENCIAS_Result> vListaFactoresCompetencias = new List <SPE_OBTIENE_FACTORES_COMPETENCIAS_Result>(); //int vFila = 2; //int vColumna = 0; DataTable vDtPivot = new DataTable(); DataTable vDtFactoresPruebas = new DataTable(); string vClaseColor = ""; string vColorEncabezado = "lightskyblue"; //string vImagen = ""; string vClasificacion = ""; vListaFactores = op.obtieneFactoresConsulta(); vListaCompetencias = op.obtieneCompetenciasConsulta(); vListaFactoresCompetencias = op.obtieneFactoresCompetencias(); vDtFactoresPruebas = ObtieneDataTableCompetencias(); vListaDetallada = op.obtieneConsultaPersonalDetallada(pIdBateria); bool vFgValidaTiva = true; int vResBaremos = 0; decimal vTvTotal = 0; //Se agregan los dos lineas siguientes para obtener las variables baremos sin relacionar con competencias PruebasNegocio pruebas = new PruebasNegocio(); var vBaremos = pruebas.obtenerVariableBaremos(pIdBateria); if (vListaDetallada.Count > 0) { if (vListaDetallada.Exists(e => e.CL_VARIABLE == "TV-TOTAL")) { vTvTotal = Math.Round(vListaDetallada.Where(w => w.CL_VARIABLE == "TV-TOTAL").Select(s => s.NO_VALOR).FirstOrDefault(), 0); } } foreach (var item in vBaremos) { if (item.CL_VARIABLE == "L1-CONSTANCIA" || item.CL_VARIABLE == "L1-CUMPLIMIENTO" || item.CL_VARIABLE == "L2-MANTIENE Y CONSERVA" || item.CL_VARIABLE == "IN-REGULATORIO") { if (vTvTotal == 1) { vResBaremos += (item.NO_VALOR == 1 || item.NO_VALOR == 2) ? 1 : 0; } if (vTvTotal == 2) { vResBaremos += (item.NO_VALOR == 3 || item.NO_VALOR == 2) ? 1 : 0; } if (vTvTotal == 3) { vResBaremos += (item.NO_VALOR == 3 || item.NO_VALOR == 2) ? 1 : 0; } } } if ((4 - vResBaremos) >= 2) { vFgValidaTiva = false; } vDtPivot.Columns.Add("CL_COLOR", typeof(string)); vDtPivot.Columns.Add("NB_COMPETENCIA", typeof(string)); foreach (var item in vListaFactores) { vDtPivot.Columns.Add(item.ID_FACTOR.ToString() + "E", typeof(int)); } foreach (var vCom in vListaCompetencias) { DataRow vDr = vDtPivot.NewRow(); if (!vClasificacion.Equals(vCom.NB_CLASIFICACION_COMPETENCIA)) { vClasificacion = vCom.NB_CLASIFICACION_COMPETENCIA; DataRow vDrClasificacion = vDtPivot.NewRow(); vDrClasificacion["CL_COLOR"] = vCom.CL_COLOR; vDrClasificacion["NB_COMPETENCIA"] = vCom.NB_CLASIFICACION_COMPETENCIA; vDtPivot.Rows.Add(vDrClasificacion); vDrClasificacion = null; } vClaseColor = string.Format(vCom.CL_COLOR); vDr["NB_COMPETENCIA"] = vCom.NB_COMPETENCIA; foreach (var vFac in vListaFactores) { var vResultado = vListaDetallada.Where(t => t.ID_COMPETENCIA == vCom.ID_COMPETENCIA & t.ID_FACTOR == vFac.ID_FACTOR).FirstOrDefault(); if (vResultado != null) { if (vResultado.NB_PRUEBA == "TIVA" && vFgValidaTiva == false) { vDr[vFac.ID_FACTOR.ToString() + "E"] = "-1"; } else { int vNum = (int)vResultado.NO_VALOR; if (vNum == 0) { vDr[vFac.ID_FACTOR.ToString() + "E"] = "-1"; } else { vDr[vFac.ID_FACTOR.ToString() + "E"] = vNum; } } } else { var vBuscarResultado = vListaFactoresCompetencias.Where(t => t.ID_COMPETENCIA == vCom.ID_COMPETENCIA & t.ID_FACTOR == vFac.ID_FACTOR).FirstOrDefault(); if (vBuscarResultado != null) { vDr[vFac.ID_FACTOR.ToString() + "E"] = "-1"; } } } vDtPivot.Rows.Add(vDr); } using (ExcelPackage pck = new ExcelPackage(newStream)) { var ws = pck.Workbook.Worksheets.Add("ConsultaPersonalDetallada"); ws.Cells["B1"].Value = "Consulta personal detallada"; ws.Cells["B1"].Style.Font.Size = 18; ws.Cells["B1"].Style.Font.Color.SetColor(System.Drawing.Color.IndianRed); ws.Cells["B3"].Value = "Folio de solicitud: " + pClFolio + " Candidato: " + pNbCandidato; ws.Cells["B3"].Style.Font.Bold = true; asignarEstiloCelda(ws.Cells["B3:C3"], "PowderBlue", false); //Datos de pruebas y competencias ws.Cells["A7"].LoadFromDataTable(vDtPivot, false); //Encabezados ws.Cells["C5"].LoadFromDataTable(vDtFactoresPruebas, false); ws.Column(2).AutoFit(); //Ahora, vamos a realizar un loop para hacer el merge de las columnas de las pruebas y ver como queda int vNoColumnas = vDtFactoresPruebas.Columns.Count; int vNoFilas = vDtPivot.Columns.Count; int vColumnaInicial = 3; int vColumnaFinal = 3; int vFilaPruebas = 5; int vFilaFactores = 6; int vFilaDatos = 7; string vNbPrueba = ws.Cells[vFilaPruebas, vColumnaInicial].Value.ToString(); bool vFgRealizaMerge = false; //Iteramos las filas para encontrar la fila de la clasificación y dibujarla for (int i = 1; i <= vNoFilas + 1; i++) { if (ws.Cells[vFilaDatos, 1].Value != null) { vClaseColor = ws.Cells[vFilaDatos, 1].Value.ToString(); ws.Cells[vFilaDatos, 1, vFilaDatos, (vNoColumnas + 2)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[vFilaDatos, 1, vFilaDatos, (vNoColumnas + 2)].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromName(vClaseColor)); ws.Cells[vFilaDatos, 1, vFilaDatos, (vNoColumnas + 2)].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Medium, System.Drawing.Color.Black); ws.Cells[vFilaDatos, 1, vFilaDatos, (vNoColumnas + 2)].Style.Font.Bold = true; } vFilaDatos++; } //Iteramos las columnas para hacer el merge de los titulos de las pruebas y cambiar la orientación de los factores de las pruebas, tambien acomodamos el tamaño de las columnas for (int i = 1; i <= vNoColumnas + 1; i++) { if (ws.Cells[vFilaPruebas, vColumnaFinal].Value == null) { vFgRealizaMerge = true; } else { if (!ws.Cells[vFilaPruebas, vColumnaFinal].Value.ToString().Equals(vNbPrueba)) { vFgRealizaMerge = true; } } if (vFgRealizaMerge) { //aplicamos el merge y el centrado al título de la prueba ws.Cells[vFilaPruebas, vColumnaInicial, vFilaPruebas, (vColumnaFinal - 1)].Merge = true; ws.Cells[vFilaPruebas, vColumnaInicial].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; //Agregamos el color y el borde ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromName(vColorEncabezado)); //ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Medium, System.Drawing.Color.Black); ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; ws.Cells[vFilaPruebas, vColumnaInicial, vFilaFactores, (vColumnaFinal - 1)].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; if (vColorEncabezado.Equals("lightskyblue")) { vColorEncabezado = "white"; } else { vColorEncabezado = "lightskyblue"; } if (ws.Cells[vFilaPruebas, vColumnaFinal].Value != null) { vNbPrueba = ws.Cells[vFilaPruebas, vColumnaFinal].Value.ToString(); } else { vNbPrueba = ""; } vColumnaInicial = vColumnaFinal; vFgRealizaMerge = false; } ws.Cells[vFilaFactores, vColumnaFinal].Style.TextRotation = 180; ws.Cells[vFilaFactores, vColumnaFinal].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top; vColumnaFinal++; } //Aqui estams metiendo las formulas necesarias para que ponga el color según el valor var conditionalFormattingRule01 = ws.ConditionalFormatting.AddEqual(ws.Cells[3, 3, (vNoFilas + 3), (vNoColumnas + 3)]); conditionalFormattingRule01.Formula = "3"; conditionalFormattingRule01.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; conditionalFormattingRule01.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Green; conditionalFormattingRule01.Style.Font.Color.Color = System.Drawing.Color.Green; conditionalFormattingRule01.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule01.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule01.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule01.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; var conditionalFormattingRule02 = ws.ConditionalFormatting.AddEqual(ws.Cells[3, 3, (vNoFilas + 3), (vNoColumnas + 3)]); conditionalFormattingRule02.Formula = "2"; conditionalFormattingRule02.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; conditionalFormattingRule02.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Yellow; conditionalFormattingRule02.Style.Font.Color.Color = System.Drawing.Color.Yellow; conditionalFormattingRule02.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule02.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule02.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule02.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; var conditionalFormattingRule03 = ws.ConditionalFormatting.AddEqual(ws.Cells[3, 3, (vNoFilas + 3), (vNoColumnas + 3)]); conditionalFormattingRule03.Formula = "1"; conditionalFormattingRule03.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; conditionalFormattingRule03.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Red; conditionalFormattingRule03.Style.Font.Color.Color = System.Drawing.Color.Red; conditionalFormattingRule03.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule03.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule03.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule03.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; var conditionalFormattingRule04 = ws.ConditionalFormatting.AddEqual(ws.Cells[3, 3, (vNoFilas + 3), (vNoColumnas + 3)]); conditionalFormattingRule04.Formula = "-1"; conditionalFormattingRule04.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; conditionalFormattingRule04.Style.Fill.BackgroundColor.Color = System.Drawing.Color.Gray; conditionalFormattingRule04.Style.Font.Color.Color = System.Drawing.Color.Gray; conditionalFormattingRule04.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule04.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule04.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; conditionalFormattingRule04.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Medium; ws.Column(1).Hidden = true; pck.Save(); newStream = pck.Stream; } oConsultaPersonal.NB_ARCHIVO = "ConsultaPersonalDetallada.xlsx"; oConsultaPersonal.FI_ARCHIVO = ((MemoryStream)newStream).ToArray(); return(oConsultaPersonal); }
public UDTT_ARCHIVO obtieneConsultaPersonalResumenDT(int pIdBateria, bool vFgConsultaParcial, string pNbCandidato, string pClFolio) { ConsultaPersonalOperaciones op = new ConsultaPersonalOperaciones(); UDTT_ARCHIVO oConsultaPersonal = new UDTT_ARCHIVO(); Stream newStream = new MemoryStream(); Utilerias.Utilerias aux = new Utilerias.Utilerias(); int vFila = 9; string vClCelda = ""; string vNbCategoria = ""; decimal?vPromedioBaremos = 0; //Obtenemos los datos y los pasamos a un DataTable List <SPE_OBTIENE_CONSULTA_PERSONAL_RESUMEN_Result> oLista = op.obtieneConsultaPersonalResumen(pIdBateria, vFgConsultaParcial); vPromedioBaremos = oLista.Average(t => t.NO_BAREMO_PORCENTAJE); //Creamos el archivo de excel using (ExcelPackage pck = new ExcelPackage(newStream)) { var ws = pck.Workbook.Worksheets.Add("ConsultaPersonalResumida"); ws.Column(1).Width = 50; ws.Column(2).Width = 50; ws.Column(3).Width = 50; ws.Cells["A3"].Value = "Consulta personal resumida"; ws.Cells["A3"].Style.Font.Size = 18; ws.Cells["A3"].Style.Font.Color.SetColor(System.Drawing.Color.IndianRed); ws.Cells["A5"].Value = "Folio de solicitud: " + pClFolio + " Candidato: " + pNbCandidato; ws.Cells["A5"].Style.Font.Bold = true; asignarEstiloCelda(ws.Cells["A5:B5"], "PowderBlue", false); ws.Cells["A7"].Value = "Competencia"; asignarEstiloCelda(ws.Cells["A7"], "PowderBlue"); ws.Cells["B7"].Value = "Descripción competencia"; asignarEstiloCelda(ws.Cells["B7"], "PowderBlue"); ws.Cells["C7"].Value = "Descripción del nivel"; asignarEstiloCelda(ws.Cells["C7"], "PowderBlue"); ws.Cells["D7"].Value = "Porcentaje"; asignarEstiloCelda(ws.Cells["D7"], "PowderBlue"); foreach (SPE_OBTIENE_CONSULTA_PERSONAL_RESUMEN_Result item in oLista) { //aquí verificamos la primer entrada del ciclo if (string.IsNullOrEmpty(vNbCategoria)) { vClCelda = "A" + vFila.ToString() + ":D" + vFila.ToString(); ws.Cells[vClCelda].Merge = true; vClCelda = "A" + vFila.ToString(); ws.Cells[vClCelda].Value = item.CL_CLASIFICACION; vNbCategoria = item.CL_CLASIFICACION; vClCelda = "A" + vFila.ToString() + ":D" + vFila.ToString(); asignarEstiloCelda(ws.Cells[vClCelda], item.CL_COLOR); vFila++; } //Ahora, verificamos que la clasificación sea diferente, esto para el cambio de clasificación if (!vNbCategoria.Equals(item.CL_CLASIFICACION)) { vClCelda = "A" + vFila.ToString() + ":D" + vFila.ToString(); ws.Cells[vClCelda].Merge = true; vClCelda = "A" + vFila.ToString(); ws.Cells[vClCelda].Value = item.CL_CLASIFICACION; vNbCategoria = item.CL_CLASIFICACION; vClCelda = "A" + vFila.ToString() + ":D" + vFila.ToString(); asignarEstiloCelda(ws.Cells[vClCelda], item.CL_COLOR); vFila++; } ws.Row(vFila).Style.WrapText = true; //Si no entró a ninguna de las anteriores, ponemos los datos de la competencía vClCelda = "A" + vFila.ToString(); ws.Cells[vClCelda].Value = item.NB_COMPETENCIA; asignarEstiloCelda(ws.Cells[vClCelda], item.CL_COLOR); vClCelda = "B" + vFila.ToString(); ws.Cells[vClCelda].Value = item.DS_COMPETENCIA; asignarEstiloCelda(ws.Cells[vClCelda], item.CL_COLOR); vClCelda = "C" + vFila.ToString(); ws.Cells[vClCelda].Value = item.DS_NIVEL_COMPETENCIA_PERSONA; asignarEstiloCelda(ws.Cells[vClCelda]); vClCelda = "D" + vFila.ToString(); ws.Cells[vClCelda].Value = item.NO_BAREMO_PORCENTAJE.Value.ToString("N2") + "%"; asignarEstiloCelda(ws.Cells[vClCelda], alineacion: OfficeOpenXml.Style.ExcelHorizontalAlignment.Right); vFila++; } vFila++; vClCelda = "A" + vFila.ToString(); ws.Cells[vClCelda].Value = "Compatibilidad: " + vPromedioBaremos.Value.ToString("N2") + "%"; ws.Cells[vClCelda].Style.Font.Bold = true; pck.Save(); newStream = pck.Stream; } oConsultaPersonal.NB_ARCHIVO = "ConsultaPersonalResumida.xlsx"; oConsultaPersonal.FI_ARCHIVO = ((MemoryStream)newStream).ToArray(); return(oConsultaPersonal); }
public UDTT_ARCHIVO ExportarDatosExcel(int?ID_PERIODO, int?ID_DEPARTAMENTO, string NB_DEPARTAMENTO, string DS_PRIORIDADES, int?vIdRol) { NecesidadesCapacitacionOperaciones op = new NecesidadesCapacitacionOperaciones(); PeriodoOperaciones neg = new PeriodoOperaciones(); List <SPE_OBTIENE_NECESIDADES_CAPACITACION_Result> lista = new List <SPE_OBTIENE_NECESIDADES_CAPACITACION_Result>(); SPE_OBTIENE_FYD_PERIODO_EVALUACION_Result periodo = new SPE_OBTIENE_FYD_PERIODO_EVALUACION_Result(); UDTT_ARCHIVO excelNecesidadCapacitacion = new UDTT_ARCHIVO(); int i = 11; int col = 0; int row = 0; bool FinalListaEmpleados = false; bool CompetenciaEncontrada = false; string vDsNotas = ""; string vNbFirstRadEditorTagName = "p"; periodo = neg.ObtenerPeriodoEvaluacion(ID_PERIODO.Value); lista = op.obtenerNecesidadesCapacitacion(ID_PERIODO, ID_DEPARTAMENTO, DS_PRIORIDADES, vIdRol); Stream newStream = new MemoryStream(); using (ExcelPackage pck = new ExcelPackage(newStream)) { var ws = pck.Workbook.Worksheets.Add("Reporte"); ws.View.ShowGridLines = false; //ponemos los encabezados con los datos del periodo ws.Cells["A1"].Value = "Periodo:"; ws.Cells["B1"].Value = periodo.NB_PERIODO; ws.Cells["A2"].Value = "Notas:"; if (periodo.DS_NOTAS != null) { XElement vNota = XElement.Parse(periodo.DS_NOTAS); if (vNota != null) { if (vNota.Element("DS_NOTAS") != null) { vDsNotas = vNota.Element("DS_NOTAS").Value; } } } ws.Cells["B2"].Value = vDsNotas; ws.Cells["A3"].Value = "Tipo de evaluacion:"; ws.Cells["A4"].Value = "Departamento:"; ws.Cells["B4"].Value = NB_DEPARTAMENTO; //Leyendas de colores del archivo de excel ws.Cells["D1:F1"].Merge = true; ws.Cells["D1"].Value = "Prioridades de Capacitación"; ws.Cells["D2"].Value = "Alta:"; ws.Cells["D3"].Value = "Intermedia:"; ws.Cells["D4"].Value = "No necesaria:"; ws.Cells["D5"].Value = "No Aplica:"; ws.Cells["F2"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F3"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F4"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F5"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["F2"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red); ws.Cells["F3"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gold); ws.Cells["F4"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.White); ws.Cells["F5"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); //formato de encabezados ws.Cells["A7:A10"].Merge = true; ws.Cells["B7:B10"].Merge = true; ws.Cells["C7:C10"].Merge = true; ws.Cells["A7"].Value = "CATEGORIA"; ws.Cells["B7"].Value = "CLASIFICACION"; ws.Cells["C7"].Value = "COMPETENCIA"; ws.Cells["A7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["A7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["A7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["A7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); ws.Cells["B7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["B7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["B7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["B7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); ws.Cells["C7"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; ws.Cells["C7"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; ws.Cells["C7"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells["C7"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Lavender); //Obtenemos las distintas competencias que se generan en la DNC. var competencias = (from a in lista select new { a.NB_CLASIFICACION_COMPETENCIA, a.CL_TIPO_COMPETENCIA, a.NB_COMPETENCIA, a.CL_COLOR }).Distinct(); foreach (var item in competencias) { ws.Cells["A" + i.ToString()].Value = item.CL_TIPO_COMPETENCIA; ws.Cells["B" + i.ToString()].Value = item.NB_CLASIFICACION_COMPETENCIA; ws.Cells["C" + i.ToString()].Value = item.NB_COMPETENCIA; ws.Cells["A" + i.ToString() + ":C" + i.ToString()].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin, System.Drawing.Color.FromName(item.CL_COLOR)); i++; } ws.Column(1).AutoFit(); ws.Column(2).AutoFit(); ws.Column(3).AutoFit(); //obtenemos todos los empleados var empleados = (from a in lista select new { a.CL_DEPARTAMENTO, a.NB_DEPARTAMENTO, a.CL_EVALUADO, a.NB_EVALUADO }).Distinct(); col = 4; foreach (var item in empleados) { ws.Cells[7, col].Value = item.CL_DEPARTAMENTO; ws.Cells[8, col].Value = item.NB_DEPARTAMENTO; ws.Cells[9, col].Value = item.CL_EVALUADO; ws.Cells[10, col].Value = item.NB_EVALUADO; col++; } col = 4; row = 11; string empleado = ""; while (!FinalListaEmpleados) { var valor = ws.Cells[10, col].Value; if (valor != null) { empleado = valor.ToString(); var listaEmpleado = (from a in lista where a.NB_EVALUADO == empleado select new { a.NB_COMPETENCIA, a.PR_RESULTADO, a.NB_PRIORIDAD }); foreach (var item in listaEmpleado) { while (!CompetenciaEncontrada) { if (ws.Cells[row, 3].Value.ToString() == item.NB_COMPETENCIA) { ws.Cells[row, col].Value = item.PR_RESULTADO; ws.Cells[row, col].Style.Numberformat.Format = "0.00"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; switch (item.NB_PRIORIDAD) { case "Alta": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red); break; case "Intermedia": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gold); break; case "No Necesaria": ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.White); break; default: break; } } else { if (ws.Cells[row, col].Value == null) { ws.Cells[row, col].Value = "N/A"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); } else { if (ws.Cells[row, col].Value.ToString() == "N/A") { ws.Cells[row, col].Value = "N/A"; ws.Cells[row, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; ws.Cells[row, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray); } } } if (ws.Cells[row + 1, 3].Value == null) { CompetenciaEncontrada = true; } row++; } row = 11; CompetenciaEncontrada = false; } ws.Column(col).AutoFit(); col++; } else { FinalListaEmpleados = true; } } pck.Save(); newStream = pck.Stream; } excelNecesidadCapacitacion.NB_ARCHIVO = "ReporteDNC.xlsx"; excelNecesidadCapacitacion.FI_ARCHIVO = ((MemoryStream)newStream).ToArray(); return(excelNecesidadCapacitacion); }
public UDTT_ARCHIVO ListaAsistencia(int pIdEvento, int?pIdRol) { EventoCapacitacionOperaciones op = new EventoCapacitacionOperaciones(); UDTT_ARCHIVO excelListaAsistencia = new UDTT_ARCHIVO(); SPE_OBTIENE_EVENTO_LISTA_ASISTENCIA_Result oDatos = op.ObtenerDatosListaAsistencia(pIdEvento, pIdRol); Stream newStream = new MemoryStream(); int vRow; int vCol; if (oDatos.XML_EVENTO_PARTICIPANTE != null) { using (ExcelPackage pck = new ExcelPackage(newStream)) { var ws = pck.Workbook.Worksheets.Add("ListaAsistencia"); ws.View.ShowGridLines = false; //Agregamos los datos generales del evento XElement xmlEvento = XElement.Parse(oDatos.XML_EVENTO); ws.Cells["A3"].Value = "Clave del evento:"; ws.Cells["B3"].Value = UtilXML.ValorAtributo <string>(xmlEvento.Attribute("CL_EVENTO")); ws.Cells["A4"].Value = "Descripción:"; ws.Cells["B4"].Value = UtilXML.ValorAtributo <string>(xmlEvento.Attribute("NB_EVENTO")); ws.Cells["A5"].Value = "Nombre del curso:"; ws.Cells["B5"].Value = UtilXML.ValorAtributo <string>(xmlEvento.Attribute("NB_CURSO")); ws.Cells["A6"].Value = "Nombre del instructor:"; ws.Cells["B6"].Value = UtilXML.ValorAtributo <string>(xmlEvento.Attribute("NB_INSTRUCTOR")); //agregamos los datos de los participantes del evento if (oDatos.XML_EVENTO_PARTICIPANTE != null) { XElement xmlParticipantes = XElement.Parse(oDatos.XML_EVENTO_PARTICIPANTE); vRow = 13; vCol = 1; foreach (XElement item in xmlParticipantes.Elements("PARTICIPANTE")) { ws.Cells[vRow, vCol].Value = UtilXML.ValorAtributo <string>(item.Attribute("CL_PARTICIPANTE")); vCol++; ws.Cells[vRow, vCol].Value = UtilXML.ValorAtributo <string>(item.Attribute("NB_PARTICIPANTE")); vCol++; ws.Cells[vRow, vCol].Value = UtilXML.ValorAtributo <string>(item.Attribute("NB_PUESTO")); //vCol++; //ws.Cells[vRow, vCol].Value = UtilXML.ValorAtributo<string>(item.Attribute("NB_DEPARTAMENTO")); vCol = 1; vRow++; } ws.Column(1).BestFit = true; ws.Column(1).AutoFit(); ws.Column(2).BestFit = true; ws.Column(2).AutoFit(); ws.Column(3).BestFit = true; ws.Column(3).AutoFit(); ws.Column(4).BestFit = true; ws.Column(4).AutoFit(); ws.Column(5).BestFit = true; XElement xmlCalendario = null; //Agregamos los datos del calendario del evento if (oDatos.XML_EVENTO_CALENDARIO != null) { xmlCalendario = XElement.Parse(oDatos.XML_EVENTO_CALENDARIO); } vRow = 11; vCol = 4; //OfficeOpenXml.Style.ExcelStyle oEstilo = new OfficeOpenXml.Style.ExcelStyle(); if (xmlCalendario != null) { foreach (XElement item in xmlCalendario.Elements("FECHA")) { DateTime vFeInicial, vFeFinal; vFeInicial = UtilXML.ValorAtributo <DateTime>(item.Attribute("FE_INICIAL")); vFeFinal = UtilXML.ValorAtributo <DateTime>(item.Attribute("FE_FINAL")); ws.Cells[vRow, vCol].Value = vFeInicial.ToString("dd/MM/yyyy"); asignarEstiloCelda(ws.Cells[vRow, vCol]); vRow++; ws.Cells[vRow, vCol].Value = "De " + vFeInicial.ToString("hh:mm") + " a " + vFeFinal.ToString("hh:mm"); asignarEstiloCelda(ws.Cells[vRow, vCol]); ws.Column(vCol).BestFit = true; ws.Column(vCol).AutoFit(); vRow = 11; vCol++; } } //Agregamos los encabezados de la tabla asignarEstiloCelda(ws.Cells["A11:A12"]); ws.Cells["A11:A12"].Merge = true; ws.Cells["A11"].Value = "Clave Empleado"; asignarEstiloCelda(ws.Cells["B11:B12"]); ws.Cells["B11:B12"].Merge = true; ws.Cells["B11"].Value = "Nombre de participante"; asignarEstiloCelda(ws.Cells["C11:C12"]); ws.Cells["C11:C12"].Merge = true; ws.Cells["C11"].Value = "Puesto"; //asignarEstiloCelda(ws.Cells["D11:D12"]); //ws.Cells["D11:D12"].Merge = true; //ws.Cells["D11"].Value = "Departamento"; vCol--; if (xmlCalendario != null) { asignarEstiloCelda(ws.Cells[10, 4, 10, vCol]); ws.Cells[10, 4, 10, vCol].Merge = true; ws.Cells[10, 4].Value = "Fechas/Firmas"; vRow = 13; vCol = 4; int noTotalFechas = xmlCalendario.Elements("FECHA").Count() - 1; int noTotalParticipantes = xmlParticipantes.Elements("PARTICIPANTE").Count() - 1; noTotalParticipantes = vRow + noTotalParticipantes; for (vRow = 13; vRow <= noTotalParticipantes; vRow++) { ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black); ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Left.Color.SetColor(System.Drawing.Color.Black); ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; ws.Cells[vRow, vCol, vRow, (vCol + noTotalFechas)].Style.Border.Right.Color.SetColor(System.Drawing.Color.Black); } } pck.Save(); newStream = pck.Stream; } } } excelListaAsistencia.NB_ARCHIVO = "ListaAsistencia.xlsx"; excelListaAsistencia.FI_ARCHIVO = ((MemoryStream)newStream).ToArray(); return(excelListaAsistencia); }