Esempio n. 1
0
        private void btn_exportar_excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog ruta = new SaveFileDialog();

            ruta.InitialDirectory = "\\C";
            ruta.RestoreDirectory = true;
            ruta.Title            = "Seleccionar la ruta donde guardará el Reporte";
            ruta.DefaultExt       = "xlsx";
            ruta.FileName         = "Reporte " + DateTime.Now.ToString("dd-MM-yyyy");
            ruta.Filter           = "Archivo Hoja de Calculo (*.xlsx)|*.xlsx";
            ruta.CheckPathExists  = true;

            bool check = ruta.ShowDialog() == DialogResult.OK;

            if (check)
            {
                ManejadorPageSites manejador = new ManejadorPageSites();
                bool finished = manejador.exportar_excel(datos, ruta.FileName);

                if (finished)
                {
                    MessageBox.Show("Se generó el reporte correctamente", "Reporte Generado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Ocurrió un error durante el generado del reporte", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        protected void btn_excel_Click(object sender, EventArgs e)
        {
            if (datos != null)
            {
                string nombre_archivo = "Reporte " + DateTime.Now.ToString("dd-MM-yyyy") + ".xlsx";

                ManejadorPageSites manejador = new ManejadorPageSites();
                string path = Server.MapPath("~/" + nombre_archivo);
                bool finished = manejador.exportar_excel(datos, path);

                if (finished)
                {
                    byte[] Content = File.ReadAllBytes(path);
                    Response.ContentType = "text/csv";
                    Response.AddHeader("content-disposition", "attachment; filename=" + nombre_archivo);
                    Response.BufferOutput = true;
                    Response.OutputStream.Write(Content, 0, Content.Length);
                    Response.End();
                }
            }
        }