public ActionResult EnrollmentControl2(EnrollmentControlModel m) { return View(m); }
public ActionResult EnrollmentControl(bool? excel, EnrollmentControlModel m) { if (excel != true) return new EnrollmentControlResult {model = m}; var d = from p in m.list() orderby p.Name select p; var workbook = new HSSFWorkbook(); // todo: Convert all Excel exports to this approach var sheet = workbook.CreateSheet("EnrollmentControl"); var rowIndex = 0; var row = sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue("PeopleId"); row.CreateCell(1).SetCellValue("Name"); row.CreateCell(2).SetCellValue("Organization"); row.CreateCell(3).SetCellValue("Location"); row.CreateCell(4).SetCellValue("MemberType"); rowIndex++; sheet.DisplayRowColHeadings = true; foreach (var i in d) { row = sheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue(i.Id); row.CreateCell(1).SetCellValue(i.Name); row.CreateCell(2).SetCellValue(i.Organization); row.CreateCell(3).SetCellValue(i.Location); row.CreateCell(4).SetCellValue(i.MemberType); rowIndex++; } sheet.AutoSizeColumn(0); sheet.AutoSizeColumn(1); sheet.AutoSizeColumn(2); sheet.AutoSizeColumn(3); sheet.AutoSizeColumn(4); string saveAsFileName = string.Format("EnrollmentControl-{0:d}.xls", DateTime.Now); var ms = new MemoryStream(); workbook.Write(ms); return File(ms.ToArray(), "application/vnd.ms-excel", "attachment;filename=" + saveAsFileName); }