public void GenerarReporteTurno(string Periodo) { var NombreExcel = "Reporte Turno"; // Recuperamos la data de las consulta DB var bussingLogic = new GP.BusinessLogic.BLReporte(); var data = bussingLogic.GetReporteTurno(Periodo); string[] Cabezeras = { "Nombre y Apellido", "Turno", "Asistencia", "Tardanzas", "Faltas" }; var wb = ReporteExcel.GenerarExcel(NombreExcel, Cabezeras, data.Data); var nameFile = NombreExcel + "_" + DateTime.Now.ToString("dd_MM_yyyy HH:mm:ss") + ".xlsx"; Response.AddHeader("content-disposition", "attachment; filename=" + nameFile); Response.ContentType = "application/octet-stream"; Stream outStream = Response.OutputStream; wb.Write(outStream); outStream.Close(); Response.End(); }
protected void _btnExportarExcel_Click(object sender, EventArgs e) { List <List <string> > contenido = new List <List <string> >(); List <string> fila = new List <string>(); string[] badChars = { "á", "é", "í", "ó", "ú", "ñ" }; string[] goodChars = { "á", "é", "í", "ó", "ú", "ñ" }; foreach (GridViewRow r in _gvwEventos.Rows) { for (int i = 0; i < r.Cells.Count; i++) { string text = r.Cells[i].Text; for (int k = 0; k < badChars.Length; k++) // Limpiar caracteres { text = text.Replace(badChars[k], goodChars[k]); // Quitar tildes u caracteres especiales del nombre } fila.Add(text); } contenido.Add(fila); fila = new List <string>(); } ReporteExcel report = new ReporteExcel(); SpreadsheetGear.IWorkbook workbook = report.generarReporte("Bitacora " + _txtFechaConsulta.Text.Replace('/', '-'), new List <string> { "Fecha", "Operador", "Evento" }, contenido); Thread STAThread = new Thread(() => { // Stream the Excel spreadsheet to the client in a format // compatible with Excel 97/2000/XP/2003/2007/2010. Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + "Bitacora " + _txtFechaConsulta.Text + ".xls"); workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8); Response.End(); }); STAThread.SetApartmentState(ApartmentState.STA); STAThread.Start(); STAThread.Join(); }
/// <summary> /// Método para obtener el Reporte en Excel. /// </summary> /// <returns></returns> public ActionResult ObtenerReporteExcel() { byte[] pdfQR = null; MemoryStream streamReporteExcel = null; try { ReporteExcel objReporteExcel = new ReporteExcel(); streamReporteExcel = objReporteExcel.GenerarReporteExcel(info_DataTable, titulo_Reporte, lab_Filtro, (string)Session["NombresUsuario"]); pdfQR = streamReporteExcel.ToArray(); streamReporteExcel.Flush(); streamReporteExcel.Dispose(); Logs.Info("Reporte Excel generado correctamente."); } catch (Exception e) { Logs.Error(string.Format("No se ha podido generar el reporte Excel: {0}", e.Message)); } return(File(pdfQR, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", string.Format("Reporte.{0}.{1}.{2}", titulo_Reporte, DateTime.Now.ToString("dd-MM-yyyy.hh-mm-ss"), "xlsx"))); }
private void btnExcel_Click(object sender, EventArgs e) { try { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Excel|*.xlsx", FileName = $"REPORTE BALANCE DE SITUACIÓN {GlobalConfig.Compañia.ToString()}" }) { if (sfd.ShowDialog() == DialogResult.OK) { ReporteExcel.ReporteUtilidadPerdida(ConverRowsToExcel(), Encabezado(), sfd.FileName); // CapaEntidad.Reportes.ReporteBalanceSituacion.GenerarReporte(sfd.FileName, ListaCuentasBalanceSitucion.ToList(),TotalPerdida,TotalSituacion, GlobalConfig.Compañia, GlobalConfig.Usuario); } } } catch (Exception ex) { MessageBox.Show(ex.Message, TextoGeneral.NombreApp, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnExcel_Click(object sender, EventArgs e) { try { using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Excel|*.xlsx", FileName = $"REPORTE DE PERDIDAS Y GANANCIAS {GlobalConfig.Compañia.ToString()}" }) { if (sfd.ShowDialog() == DialogResult.OK) { ReporteExcel.ReporteUtilidadPerdida(ConverRowsToExcel(), Encabezado(), sfd.FileName); //ReportePerdidasGanancias.GenerarReporte(sfd.FileName, _lstExcel.ToList(), GlobalConfig.Compañia, GlobalConfig.Usuario); } } } catch (Exception ex) { MessageBox.Show(ex.Message, TextoGeneral.NombreApp, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Método que se encarga de cargar una imagen en memoria cargada en el componente Input para carga de archivos /// </summary> /// <returns>Retorna uan arreglo de bytes con la imagen</returns> protected void _btnConsultar_Click(object sender, EventArgs e) { Usuario user = null; int contador = 0; _controladorSGC = new ControladorSGC(); _imgMensajeBusqueda.Visible = false; _lblMensajeBusqueda.Visible = false; _sesion = new Sesion(); _cookieActual = _sesion.verificarValidez(Request.Cookies["PS"]); if (_cookieActual == null) // Si la cookie expira redirecciona a la pantalla de Login { Response.Redirect("../Autentificacion/Login.aspx"); } else // Volver a crear la cookie en el cliente, con el nuevo tiempo de expiración { Response.SetCookie(_cookieActual); } // Verificar que se haya selecionado un criterio de búsqueda if (_ddlCriterio.SelectedIndex == 0) { // _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png"; _lblMensajeBusqueda.Text = "Debe seleccionar un criterio de búsqueda"; _imgMensajeBusqueda.Visible = true; _lblMensajeBusqueda.Visible = true; return; } if (_ddlCriterio.SelectedIndex == 3) //si el criterio seleccionado es por rango de fechas { // Verificar que los campos de la busqueda estén llenos if ((_txtValor2.Text.Equals("")) || (_txtValor3.Text.Equals(""))) { _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png"; _lblMensajeBusqueda.Text = "Debe ingresar fechas para la busqueda"; _imgMensajeBusqueda.Visible = true; _lblMensajeBusqueda.Visible = true; return; } else { DateTime fechaInicial = DateTime.ParseExact(_txtValor2.Text, "dd/MM/yyyy", null); DateTime fechaFinal = DateTime.ParseExact(_txtValor3.Text, "dd/MM/yyyy", null); try { List <List <string> > contenido = _controladorSGC.crearArchivoUsuariosPorFecha(fechaInicial, fechaFinal); string nombreArchivo = "Cuentas entre " + fechaInicial.Date.Day.ToString() + "-" + fechaInicial.Month.ToString() + "-" + fechaInicial.Year.ToString() + " y " + fechaFinal.Day.ToString() + "-" + fechaFinal.Month.ToString() + "-" + fechaFinal.Year.ToString(); ReporteExcel report = new ReporteExcel(); SpreadsheetGear.IWorkbook workbook = report.generarReporte(nombreArchivo, new List <string> { "Login", "Carrera", "Fecha de Creación" }, contenido); Thread STAThread = new Thread(() => { // Stream the Excel spreadsheet to the client in a format // compatible with Excel 97/2000/XP/2003/2007/2010. Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + nombreArchivo + ".xls"); workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8); Response.End(); }); STAThread.SetApartmentState(ApartmentState.STA); STAThread.Start(); STAThread.Join(); } catch (Exception ex) { _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png"; _lblMensajeBusqueda.Text = ex.Message; _imgMensajeBusqueda.Visible = true; _lblMensajeBusqueda.Visible = true; } } } else { // Verificar que los campos de la busqueda estén llenos if (_txtValor.Text.Equals("")) { _imgMensajeBusqueda.ImageUrl = "../Imagenes/Advertencia.png"; _lblMensajeBusqueda.Text = "Debe ingresar algún valor para la busqueda"; _imgMensajeBusqueda.Visible = true; _lblMensajeBusqueda.Visible = true; return; } // El criterio seleccionado es "Login" if (_ddlCriterio.SelectedIndex == 1) { user = _controladorSGC.buscarUsuario(_txtValor.Text, true); // Login } if (_ddlCriterio.SelectedIndex == 2) { user = _controladorSGC.buscarUsuario(_txtValor.Text, false); //Carnet _lblUsuario.Visible = true; _txtUsuario.Visible = true; } // Se actualiza el contenido de la interfaz if (user != null) { _txtCarnet.Text = user.Carnet; _txtNombre.Text = user.Nombre; _txtPApellido.Text = user.Apellidos.Split(' ')[0]; _txtSApellido.Text = user.Apellidos.Split(' ')[1]; _txtTelefono.Text = user.TelefonoCasa; _txtCelular.Text = user.TelefonoCelular; _txtCorreo.Text = user.Correo; _txtUsuario.Text = user.UID; foreach (ListItem carrera in _ddlCarrera.Items) { if (carrera.Text == user.Carrera) { _ddlCarrera.SelectedIndex = contador; } else { contador++; } } if (user.Grupo == "Estudiante") { _rblUsarios.SelectedIndex = 0; } else { _rblUsarios.SelectedIndex = 1; } _imgMensajeBusqueda.Visible = false; _lblMensajeBusqueda.Visible = false; _bntModificar.Enabled = true; _lblMensaje.Visible = false; _imgMensaje.Visible = false; _upConsultaUsuario.Update(); } else { _imgMensajeBusqueda.ImageUrl = "../Imagenes/Error.png"; _lblMensajeBusqueda.Text = "Usuario no encontrado"; _imgMensajeBusqueda.Visible = true; _lblMensajeBusqueda.Visible = true; _txtCarnet.Text = ""; _txtNombre.Text = ""; _txtPApellido.Text = ""; _txtSApellido.Text = ""; _txtTelefono.Text = ""; _txtCelular.Text = ""; _txtCorreo.Text = ""; _txtPassword.Text = ""; _txtCPassword.Text = ""; _ddlCarrera.SelectedIndex = 0; //if(_rblUsarios.SelectedItem.Selected) // _rblUsarios.SelectedItem.Selected = false; _bntModificar.Enabled = false; } } }