コード例 #1
0
        public string descargarExcelExport(EXACTUS_CABECERA_SIS cabecera, TipoArchivo tipoArchivo)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                int total;
                var listInterfaceParcial = new dInterfaceContable().listInterfaceContableParcial(cabecera, tipoArchivo, 0, 100000, out total);
                //atributos del file
                var      nombreArchivo = string.Format("Interface Banco_{0}_{1}", cabecera.IDE_CONTRATO, DateTime.Now.ToString("yyyyMMdd"));
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath(string.Format("~/Temp/Descargas/{0}.xlsx", nombreArchivo));
                var      book          = new XSSFWorkbook();
                string[] columns       = { "CUENTA_BANCARIA", "NUMERO",  "TIPO_DOCUMENTO", "FECHA_DOCUMENTO", "CONCEPTO",        "BENEFICIARIO", "CONTRIBUYENTE",
                                           "MONTO",                 "DETALLE", "SUBTIPO",        "CENTRO_COSTO",    "CUENTA_CONTABLE", "RUBRO_1",      "RUBRO_2",      "RUBRO_3","RUBRO_4", "RUBRO_5", "PAQUETE" };
                var      sheet       = book.CreateSheet(nombreArchivo);
                var      rowBook     = sheet.CreateRow(1);
                var      headerStyle = helperStyle.setFontText(12, true, book);
                var      bodyStyle   = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }
                for (int i = 0; i < listInterfaceParcial.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    var   numberInterface = listInterfaceParcial[i].NUMERO;
                    ICell cellCuentaBan   = rowBody.CreateCell(1);
                    cellCuentaBan.SetCellValue(listInterfaceParcial[i].CUENTA_BANCARIA);
                    cellCuentaBan.CellStyle = bodyStyle;

                    ICell cellNumero = rowBody.CreateCell(2);
                    cellNumero.SetCellValue(string.Format("CB{0}{1}", new string('0', 8 - numberInterface.ToString().Length), numberInterface.ToString()));
                    cellNumero.CellStyle = bodyStyle;

                    ICell cellTipDoc = rowBody.CreateCell(3);
                    cellTipDoc.SetCellValue(listInterfaceParcial[i].TIPO_DOCUMENTO);
                    cellTipDoc.CellStyle = bodyStyle;

                    ICell cellFecDoc = rowBody.CreateCell(4);
                    cellFecDoc.SetCellValue(listInterfaceParcial[i].FECHA_DOCUMENTO.ToShortDateString());
                    cellFecDoc.CellStyle = bodyStyle;

                    ICell cellConcepto = rowBody.CreateCell(5);
                    cellConcepto.SetCellValue(listInterfaceParcial[i].CONCEPTO);
                    cellConcepto.CellStyle = bodyStyle;

                    ICell cellBenificiario = rowBody.CreateCell(6);
                    cellBenificiario.SetCellValue(listInterfaceParcial[i].BENEFICIARIO);
                    cellBenificiario.CellStyle = bodyStyle;


                    ICell cellContribuyente = rowBody.CreateCell(7);
                    cellContribuyente.SetCellValue(listInterfaceParcial[i].CONTRIBUYENTE);
                    cellContribuyente.CellStyle = bodyStyle;

                    ICell cellMonto = rowBody.CreateCell(8);
                    cellMonto.SetCellValue(listInterfaceParcial[i].MONTOSTR);
                    cellMonto.CellStyle = bodyStyle;

                    ICell cellDetalle = rowBody.CreateCell(9);
                    cellDetalle.SetCellValue(listInterfaceParcial[i].DETALLE);
                    cellDetalle.CellStyle = bodyStyle;

                    ICell cellSubTipo = rowBody.CreateCell(10);
                    cellSubTipo.SetCellValue(listInterfaceParcial[i].SUBTIPO.ToString());
                    cellSubTipo.CellStyle = bodyStyle;


                    ICell cellCentroCosto = rowBody.CreateCell(11);
                    cellCentroCosto.SetCellValue(listInterfaceParcial[i].CENTRO_COSTO);
                    cellCentroCosto.CellStyle = bodyStyle;

                    ICell cellCuentaCont = rowBody.CreateCell(12);
                    cellCuentaCont.SetCellValue(listInterfaceParcial[i].CUENTA_CONTABLE);
                    cellCuentaCont.CellStyle = bodyStyle;

                    ICell cellRubro1 = rowBody.CreateCell(13);
                    cellRubro1.SetCellValue(listInterfaceParcial[i].RUBRO_1);
                    cellRubro1.CellStyle = bodyStyle;

                    ICell cellRubro2 = rowBody.CreateCell(14);
                    cellRubro2.SetCellValue(listInterfaceParcial[i].RUBRO_2);
                    cellRubro2.CellStyle = bodyStyle;

                    ICell cellRubro3 = rowBody.CreateCell(15);
                    cellRubro3.SetCellValue(listInterfaceParcial[i].RUBRO_3);
                    cellRubro3.CellStyle = bodyStyle;

                    ICell cellRubro4 = rowBody.CreateCell(16);
                    cellRubro4.SetCellValue(listInterfaceParcial[i].RUBRO_4);
                    cellRubro4.CellStyle = bodyStyle;

                    ICell cellRubro5 = rowBody.CreateCell(17);
                    cellRubro5.SetCellValue(listInterfaceParcial[i].RUBRO_5);
                    cellRubro5.CellStyle = bodyStyle;

                    ICell cellPaquete = rowBody.CreateCell(18);
                    cellPaquete.SetCellValue(listInterfaceParcial[i].PAQUETE);
                    cellPaquete.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
        }
コード例 #2
0
        public string descargarExcel(EXACTUS_CABECERA_SIS cabecera, TipoArchivo archivo)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                int total;
                var listInterface = new dInterfaceContable().listInterfaceContable(cabecera, archivo, 0, 100000, out total);
                //atributos del file
                var      nombreArchivo = string.Format("Interface Provision_{0}_{1}", cabecera.IDE_CONTRATO, DateTime.Now.ToString("yyyyMMdd"));
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath(string.Format("~/Temp/Descargas/{0}.xlsx", nombreArchivo));
                var      book          = new XSSFWorkbook();
                string[] columns       = { "PAQUETE", "ASIENTO",         "FECHA_REGISTRO", "TIPO_ASIENTO", "CONTABILIDAD", "FUENTE",       "REFERENCIA",     "CONTRIBUYENTE",
                                           "CENTRO_COSTO",  "CUENTA_CONTABLE", "DebitoSoles",    "CreditoSoles", "DebitoDolar",  "CreditoDolar", "MONTO_UNIDADES", "NIT",          "DIMENSION1","DIMENSION2", "DIMENSION3", "DIMENSION4", "DIMENSION5" };
                var      sheet       = book.CreateSheet(nombreArchivo);
                var      rowBook     = sheet.CreateRow(1);
                var      headerStyle = helperStyle.setFontText(12, true, book);
                var      bodyStyle   = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }
                for (int i = 0; i < listInterface.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    ICell cellPaquete = rowBody.CreateCell(1);
                    cellPaquete.SetCellValue(listInterface[i].EXACTUS_CABECERA_SIS.PAQUETE);
                    cellPaquete.CellStyle = bodyStyle;

                    ICell cellAsiento = rowBody.CreateCell(2);
                    cellAsiento.SetCellValue(listInterface[i].EXACTUS_CABECERA_SIS.ASIENTO);
                    cellAsiento.CellStyle = bodyStyle;

                    ICell cellFechaReg = rowBody.CreateCell(3);
                    cellFechaReg.SetCellValue(listInterface[i].EXACTUS_CABECERA_SIS.FECHA.ToShortDateString());
                    cellFechaReg.CellStyle = bodyStyle;

                    ICell cellTipoAsiento = rowBody.CreateCell(4);
                    cellTipoAsiento.SetCellValue(listInterface[i].EXACTUS_CABECERA_SIS.TIPO_ASIENTO);
                    cellTipoAsiento.CellStyle = bodyStyle;

                    ICell cellContabilidad = rowBody.CreateCell(5);
                    cellContabilidad.SetCellValue(listInterface[i].EXACTUS_CABECERA_SIS.CONTABILIDAD);
                    cellContabilidad.CellStyle = bodyStyle;

                    ICell cellFuente = rowBody.CreateCell(6);
                    cellFuente.SetCellValue(listInterface[i].FUENTE);
                    cellFuente.CellStyle = bodyStyle;

                    ICell cellReferencia = rowBody.CreateCell(7);
                    cellReferencia.SetCellValue(listInterface[i].REFERENCIA);
                    cellReferencia.CellStyle = bodyStyle;

                    ICell cellContribuyente = rowBody.CreateCell(8);
                    cellContribuyente.SetCellValue(listInterface[i].CONTRIBUYENTE);
                    cellContribuyente.CellStyle = bodyStyle;

                    ICell cellCentroCosto = rowBody.CreateCell(9);
                    cellCentroCosto.SetCellValue(listInterface[i].CENTRO_COSTO);
                    cellCentroCosto.CellStyle = bodyStyle;

                    ICell cellCuentaCont = rowBody.CreateCell(10);
                    cellCuentaCont.SetCellValue(listInterface[i].CUENTA_CONTABLE);
                    cellCuentaCont.CellStyle = bodyStyle;

                    ICell cellDebitoSol = rowBody.CreateCell(11);
                    cellDebitoSol.SetCellValue(listInterface[i].DebitoSoles);
                    cellDebitoSol.CellStyle = bodyStyle;

                    ICell cellCreditoSol = rowBody.CreateCell(12);
                    cellCreditoSol.SetCellValue(listInterface[i].CreditoSoles);
                    cellCreditoSol.CellStyle = bodyStyle;

                    ICell cellDebitoDol = rowBody.CreateCell(13);
                    cellDebitoDol.SetCellValue(listInterface[i].DebitoDolar);
                    cellDebitoDol.CellStyle = bodyStyle;

                    ICell cellCreditoDol = rowBody.CreateCell(14);
                    cellCreditoDol.SetCellValue(listInterface[i].CreditoDolar);
                    cellCreditoDol.CellStyle = bodyStyle;

                    ICell cellMontoUnid = rowBody.CreateCell(15);
                    cellMontoUnid.SetCellValue(listInterface[i].MONTO_UNIDADES.ToString());
                    cellMontoUnid.CellStyle = bodyStyle;

                    ICell cellNit = rowBody.CreateCell(16);
                    cellNit.SetCellValue(listInterface[i].NIT);
                    cellNit.CellStyle = bodyStyle;

                    ICell cellDIMENSION1 = rowBody.CreateCell(17);
                    cellDIMENSION1.SetCellValue(listInterface[i].DIMENSION1);
                    cellDIMENSION1.CellStyle = bodyStyle;

                    ICell cellDIMENSION2 = rowBody.CreateCell(18);
                    cellDIMENSION2.SetCellValue(listInterface[i].DIMENSION2);
                    cellDIMENSION2.CellStyle = bodyStyle;

                    ICell cellDIMENSION3 = rowBody.CreateCell(19);
                    cellDIMENSION3.SetCellValue(listInterface[i].DIMENSION3);
                    cellDIMENSION3.CellStyle = bodyStyle;

                    ICell cellDIMENSION4 = rowBody.CreateCell(20);
                    cellDIMENSION4.SetCellValue(listInterface[i].DIMENSION4);
                    cellDIMENSION4.CellStyle = bodyStyle;

                    ICell cellDIMENSION5 = rowBody.CreateCell(21);
                    cellDIMENSION5.SetCellValue(listInterface[i].DIMENSION5);
                    cellDIMENSION5.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw(new Exception(ex.Message));
            }
        }
コード例 #3
0
        public string descargarConsultaExcel(HLogOperacion log, object[] filters)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                var      nombreArchivo = string.Format("Log {0}_{1}", log.IDE_CONTRATO, DateTime.Now.ToString("yyyyMMdd"));
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath("~/Temp/Descargas/" + nombreArchivo + ".xlsx");
                int      total;
                var      book        = new XSSFWorkbook();
                string[] columns     = { "Contrato", "Tabla - ID", "Tipo evento", "Fecha  evento", "Evento", "Columna - Dato", "Usuario" };
                var      sheet       = book.CreateSheet();
                var      rowBook     = sheet.CreateRow(1);
                var      headerStyle = helperStyle.setFontText(12, true, book);
                var      bodyStyle   = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }
                var listLogOperacion = getListLogOperacion(log, 0, 100000, filters, out total);
                for (int i = 0; i < listLogOperacion.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    ICell cellContrato = rowBody.CreateCell(1);
                    cellContrato.SetCellValue(listLogOperacion[i].CONTRATO_SYS.DES_CONTRATO);
                    cellContrato.CellStyle = bodyStyle;

                    ICell cellTablaId = rowBody.CreateCell(2);
                    cellTablaId.SetCellValue(listLogOperacion[i].Tabla);
                    cellTablaId.CellStyle = bodyStyle;

                    ICell cellTipoEvento = rowBody.CreateCell(3);
                    cellTipoEvento.SetCellValue(listLogOperacion[i].TipoEvento);
                    cellTipoEvento.CellStyle = bodyStyle;

                    ICell cellFechaEvento = rowBody.CreateCell(4);
                    cellFechaEvento.SetCellValue(listLogOperacion[i].FechEven.ToString());
                    cellFechaEvento.CellStyle = bodyStyle;

                    ICell cellEvento = rowBody.CreateCell(5);
                    cellEvento.SetCellValue(listLogOperacion[i].Evento);
                    cellEvento.CellStyle = bodyStyle;

                    ICell cellColDato = rowBody.CreateCell(6);
                    cellColDato.SetCellValue(listLogOperacion[i].Columna);
                    cellColDato.CellStyle = bodyStyle;

                    ICell cellUsuario = rowBody.CreateCell(7);
                    cellUsuario.SetCellValue(listLogOperacion[i].CodiUsu);
                    cellUsuario.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #4
0
        public string descargarExcelAprueba(CONTRATO_SYS contratoSis, object[] filtersNow)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                int total;
                var listDescarga = new dAprobacionCarga().listApruebaCarga(contratoSis, 0, 100000, "IdLinCab ASC", filtersNow, out total);
                //atributos del file
                var      nombreArchivo = string.Format("Aprueba {0}_{1}_{2}", filtersNow[0].ToString(), DateTime.Now.ToString("yyyyMMdd"), contratoSis.IDE_CONTRATO.ToString());
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath(string.Format("~/Temp/Descargas/{0}.xlsx", nombreArchivo));
                var      book          = new XSSFWorkbook();
                string[] columns       = { "NombreArchivo", "Fecha Carga", "Mondeda", "TotalRegistros", "TotalImporte", "FechaCreacción", "Usuario" };
                var      sheet         = book.CreateSheet(nombreArchivo);
                var      rowBook       = sheet.CreateRow(1);
                var      headerStyle   = helperStyle.setFontText(12, true, book);
                var      bodyStyle     = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }
                for (int i = 0; i < listDescarga.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    ICell cellArchivo = rowBody.CreateCell(1);
                    cellArchivo.SetCellValue(listDescarga[i].NombreArchivo);
                    cellArchivo.CellStyle = bodyStyle;

                    ICell cellFechaCarga = rowBody.CreateCell(2);
                    cellFechaCarga.SetCellValue(listDescarga[i].FechaCarga.ToShortDateString());
                    cellFechaCarga.CellStyle = bodyStyle;

                    ICell cellMoneda = rowBody.CreateCell(3);
                    cellMoneda.SetCellValue(listDescarga[i].moneda);
                    cellMoneda.CellStyle = bodyStyle;

                    ICell cellTotalRegistros = rowBody.CreateCell(4);
                    cellTotalRegistros.SetCellValue(listDescarga[i].TotalRegistros);
                    cellTotalRegistros.CellStyle = bodyStyle;

                    ICell cellTotalImporte = rowBody.CreateCell(5);
                    cellTotalImporte.SetCellValue(listDescarga[i].TotalImporte);
                    cellTotalImporte.CellStyle = bodyStyle;

                    ICell cellFechaInfo = rowBody.CreateCell(6);
                    cellFechaInfo.SetCellValue(listDescarga[i].FechaInfo.ToShortDateString());
                    cellFechaInfo.CellStyle = bodyStyle;

                    ICell cellUsuReg = rowBody.CreateCell(7);
                    cellUsuReg.SetCellValue(listDescarga[i].UsuReg);
                    cellUsuReg.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #5
0
        public string descargarConsultaExcel(CONTRATO_SYS contrato, object[] filters)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                var      nombreArchivo = "Descarga " + filters[0].ToString() + " " + DateTime.Now.ToString("yyyyMMdd");
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath("~/Temp/Descargas/" + nombreArchivo + ".xlsx");
                int      total;
                var      book        = new XSSFWorkbook();
                string[] columns     = { "Archivo", "Fecha Carga", "Usuario", "Nro Lineas", "Estado", "Moneda", "Importe" };
                var      sheet       = book.CreateSheet(nombreArchivo);
                var      rowBook     = sheet.CreateRow(1);
                var      headerStyle = helperStyle.setFontText(12, true, book);
                var      bodyStyle   = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }

                var listSegDescarga = new nSegDescarga().listSegDescarga(contrato, filters, 0, 100000, "Estado ASC", out total);
                for (int i = 0; i < listSegDescarga.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    ICell cellNombre = rowBody.CreateCell(1);
                    cellNombre.SetCellValue(listSegDescarga[i].NombreArchivo);
                    cellNombre.CellStyle = bodyStyle;

                    ICell cellFecCarga = rowBody.CreateCell(2);
                    cellFecCarga.SetCellValue(listSegDescarga[i].FechaCarga.ToShortDateString());
                    cellFecCarga.CellStyle = bodyStyle;

                    ICell cellUsuario = rowBody.CreateCell(3);
                    cellUsuario.SetCellValue(listSegDescarga[i].Usuario);
                    cellUsuario.CellStyle = bodyStyle;

                    ICell cellNroLinea = rowBody.CreateCell(4);
                    cellNroLinea.SetCellValue(listSegDescarga[i].NroLineas);
                    cellNroLinea.CellStyle = bodyStyle;

                    ICell cellEstado = rowBody.CreateCell(5);
                    cellEstado.SetCellValue(listSegDescarga[i].Estado);
                    cellEstado.CellStyle = bodyStyle;

                    ICell cellMoneda = rowBody.CreateCell(6);
                    cellMoneda.SetCellValue(listSegDescarga[i].Moneda);
                    cellMoneda.CellStyle = bodyStyle;

                    ICell cellImporte = rowBody.CreateCell(7);
                    cellImporte.SetCellValue(listSegDescarga[i].Importe);
                    cellImporte.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #6
0
        /// <summary>
        /// Crea un archivo excel acuerdo a los filtros especificados
        /// </summary>
        /// <param name="cab"></param>
        /// <param name="det"></param>
        /// <param name="filterParam"></param>
        /// <returns></returns>
        public string getDescargarConsulta(HistorialCargaArchivo_LinCab cab, NOMINA nomina, HistorialCargaArchivo_LinDet det, object[] filterParam)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                var nombreArchivo = "Archivo " + filterParam[0].ToString() + " " + DateTime.Now.ToString("yyyyMMdd");
                var rutaTemporal  = @HttpContext.Current.Server.MapPath("~/Temp/Descargas/" + nombreArchivo + ".xlsx");
                int total;
                var tipoLinea = filterParam[0].ToString() == "NOMINA" ? "*" : "D";
                //new Utils.DeleteFile().deleteFile(HttpContext.Current.Server.MapPath(@"~/Utils/xlsxs/"));
                XSSFWorkbook book        = new XSSFWorkbook();
                var          contratoSis = new nContratoSis().listContratoByID(new CONTRATO_SYS()
                {
                    IDE_CONTRATO = cab.IDE_CONTRATO
                });
                var reglaArchivo = new ReglaArchivo()
                {
                    Archivo = filterParam[0].ToString(), TipoLinea = tipoLinea, NUM_CONT_LIC = Convert.ToInt32(contratoSis.NRO_CONTRATO), vigente = 1
                };
                var listReglaArchivo = new nReglaArchivo().getListReglaArchivo(reglaArchivo, 0, 1000, "IdReglaArchivo ASC", out total);
                if (reglaArchivo.Archivo.Equals("0"))
                {
                    listReglaArchivo = listReglaArchivo.GroupBy(x => new { x.NombreCampo, x.TituloColumna })
                                       .Select(y => new ReglaArchivo()
                    {
                        NombreCampo = y.Key.NombreCampo, TituloColumna = y.Key.TituloColumna
                    }).ToList();
                }
                //crear el libro
                var sheet       = book.CreateSheet(nombreArchivo);
                var rowCabecera = sheet.CreateRow(1);
                var headerStyle = helperStyle.setFontText(12, true, book);
                var bodyStyle   = helperStyle.setFontText(11, false, book);
                //construir cabecera
                ICell cellCabecera;
                for (int i = 0; i < listReglaArchivo.Count; i++)
                {
                    cellCabecera = rowCabecera.CreateCell(i + 1);
                    cellCabecera.SetCellValue(listReglaArchivo[i].TituloColumna);
                    cellCabecera.CellStyle = headerStyle;
                }
                //consultar datos segun los filtros especificados
                if (filterParam[0].ToString() == "NOMINA")
                {
                    var listNomina = new nNomina().listNominaConsulta(nomina, filterParam, 0, 100000, out total);
                    for (int i = 0; i < listNomina.Count; i++)
                    {
                        IRow  rowBody = sheet.CreateRow(i + 2);
                        ICell cellBody;
                        for (int c = 0; c < listReglaArchivo.Count; c++)
                        {
                            cellBody = rowBody.CreateCell(c + 1);
                            var property = listNomina[i].GetType().GetProperty(listReglaArchivo[c].NombreCampo.ToString().Trim(), BindingFlags.Public | BindingFlags.Instance);
                            cellBody.SetCellValue(property.GetValue(listNomina[i], null) == null ? "" : property.GetValue(listNomina[i], null).ToString());
                            cellBody.CellStyle = bodyStyle;
                        }
                    }
                }
                else
                {
                    var listHistoriaLinDet = new dPagoCargado().listArchivoCargado(cab, det, filterParam, 0, 100000, "TipoLinea ASC", out total);
                    for (int i = 0; i < listHistoriaLinDet.Count; i++)
                    {
                        IRow  rowBody = sheet.CreateRow(i + 2);
                        ICell cellBody;
                        for (int c = 0; c < listReglaArchivo.Count; c++)
                        {
                            cellBody = rowBody.CreateCell(c + 1);
                            var property = listHistoriaLinDet[i].GetType().GetProperty(listReglaArchivo[c].NombreCampo.ToString().Trim(), BindingFlags.Public | BindingFlags.Instance);
                            cellBody.SetCellValue(property.GetValue(listHistoriaLinDet[i], null) == null ? "" : property.GetValue(listHistoriaLinDet[i], null).ToString());
                            cellBody.CellStyle = bodyStyle;
                        }
                    }
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                //guardar el archivo creado en memoria
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }
                return(rutaTemporal);
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
コード例 #7
0
        public string descargarExcelTelebankig(NOMINA nomina, string formatoMoneda)
        {
            var helperStyle = new Helpers.excelStyle();

            try
            {
                int total;
                var listDescarga = new dTelebanking().listTelebanking(nomina, 0, 100000, "NombreArchivo ASC", formatoMoneda, out total);
                //atributos del file
                var      nombreArchivo = string.Format("Nomina {0}_{1}", DateTime.Now.ToString("yyyyMMdd"), nomina.IDE_CONTRATO.ToString());
                var      rutaTemporal  = @HttpContext.Current.Server.MapPath(string.Format("~/Temp/Descargas/{0}.xlsx", nombreArchivo));
                var      book          = new XSSFWorkbook();
                string[] columns       = { "NombreArchivo", "Fecha Operación", "Moneda", "Importe" };
                var      sheet         = book.CreateSheet(nombreArchivo);
                var      rowBook       = sheet.CreateRow(1);
                var      headerStyle   = helperStyle.setFontText(12, true, book);
                var      bodyStyle     = helperStyle.setFontText(11, false, book);
                ICell    cellBook;
                for (int i = 0; i < columns.Length; i++)
                {
                    cellBook = rowBook.CreateCell(i + 1);
                    cellBook.SetCellValue(columns[i]);
                    cellBook.CellStyle = headerStyle;
                }
                for (int i = 0; i < listDescarga.Count; i++)
                {
                    var rowBody = sheet.CreateRow(2 + i);

                    ICell cellArchivo = rowBody.CreateCell(1);
                    cellArchivo.SetCellValue(listDescarga[i].NombreArchivo);
                    cellArchivo.CellStyle = bodyStyle;

                    ICell cellFechaCarga = rowBody.CreateCell(2);
                    cellFechaCarga.SetCellValue(listDescarga[i].FechaOperacion.ToShortDateString());
                    cellFechaCarga.CellStyle = bodyStyle;

                    ICell cellMoneda = rowBody.CreateCell(3);
                    cellMoneda.SetCellValue(listDescarga[i].Moneda);
                    cellMoneda.CellStyle = bodyStyle;

                    ICell cellTotalRegistros = rowBody.CreateCell(4);
                    cellTotalRegistros.SetCellValue(listDescarga[i].Importe);
                    cellTotalRegistros.CellStyle = bodyStyle;
                }
                if (File.Exists(rutaTemporal))
                {
                    File.Delete(rutaTemporal);
                }
                using (var file = new FileStream(rutaTemporal, FileMode.Create, FileAccess.ReadWrite))
                {
                    book.Write(file);
                    file.Close();
                    book.Close();
                }

                return(rutaTemporal);
            }
            catch (Exception ex)
            {
                throw(new Exception(ex.Message));
            }
        }