public async Task <IActionResult> DescargarReporte() { AdminSession sesion = new AdminSession(HttpContext); List <ClsInfoInformQuejas> data = sesion.GetObject <List <ClsInfoInformQuejas> >(VariablesDeSession.DataReporte); if (data != null) { var stream = new MemoryStream(); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; await Task.Yield(); // var list = new List<UserInfo>() //{ // new UserInfo { UserName = "******", Age = 18 }, // new UserInfo { UserName = "******", Age = 20 }, //}; PropertyInfo[] properties = typeof(ClsInfoInformQuejas).GetProperties(); using (var package = new ExcelPackage(stream)) { var workSheet = package.Workbook.Worksheets.Add("Sheet1"); //C1 - J3 using (ExcelRange Title = workSheet.Cells[1, 1, 1, properties.Length - 6]) { Title.Merge = true; Title.Style.Font.Size = 18; Title.Style.Font.Bold = true; Title.Style.VerticalAlignment = ExcelVerticalAlignment.Center; Title.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; Title.Value = "REPORTE DE QUEJAS"; } var datos = (from d in data select new { d.Empresa, d.Region, d.Ubicacion, d.Direccion, d.Estado, d.FechaCreacion, d.FechaModificacion }).ToList(); workSheet.Cells[4, 1].Value = "Establecimiento"; workSheet.Cells[4, 1].Style.Font.Bold = true; workSheet.Cells[4, 2].Value = "Región"; workSheet.Cells[4, 2].Style.Font.Bold = true; workSheet.Cells[4, 3].Value = "Ubicación"; workSheet.Cells[4, 3].Style.Font.Bold = true; workSheet.Cells[4, 4].Value = "Dirección"; workSheet.Cells[4, 4].Style.Font.Bold = true; workSheet.Cells[4, 5].Value = "Estado"; workSheet.Cells[4, 5].Style.Font.Bold = true; workSheet.Cells[4, 6].Value = "Fecha creación"; workSheet.Cells[4, 6].Style.Font.Bold = true; workSheet.Cells[4, 7].Value = "Fecha resolución"; workSheet.Cells[4, 7].Style.Font.Bold = true; workSheet.Cells[5, 1].LoadFromCollection(datos); workSheet.Cells.AutoFitColumns(); package.Save(); } stream.Position = 0; string excelName = $"Reporte_de_quejas" + $"-{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx"; //return File(stream, "application/octet-stream", excelName); return(File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", excelName)); } else { return(Ok()); } }