// // GET: /Class/Details/5 public ActionResult Details(int id) { IQueryable <Class> modelclass = bllClass.Details(c => c.ClassForm == id); if (modelclass == null) { return(HttpNotFound()); } return(View(modelclass)); }
public ActionResult ExportExcel(int subID) { List <Student> students = new List <Student>(); var studentsid = selectSub.GetAll().Where(c => c.SubID == subID); foreach (var item in studentsid) { students.Add(bLLStudent.Details(c => c.StuID == item.StuID).FirstOrDefault()); } MemoryStream stream = new MemoryStream(); var workbook = new HSSFWorkbook(); var sheet = workbook.CreateSheet(); var headerRow = sheet.CreateRow(0); headerRow.CreateCell(0).SetCellValue("ID"); headerRow.CreateCell(1).SetCellValue("学生姓名"); headerRow.CreateCell(2).SetCellValue("学生学号"); headerRow.CreateCell(3).SetCellValue("学生班级"); for (int i = 0; i < students.Count; i++) { foreach (var item in students) { var newRow = sheet.CreateRow(i + 1); newRow.CreateCell(0).SetCellValue(item.StuID); newRow.CreateCell(1).SetCellValue(item.StuName); newRow.CreateCell(2).SetCellValue(item.StuNum); newRow.CreateCell(3).SetCellValue(bllClass.Details(c => c.ClassForm == item.ClassForm).FirstOrDefault().ClassNum); } } workbook.Write(stream); stream.Flush(); stream.Position = 0; sheet = null; headerRow = null; workbook = null; return(File(stream, "application/vnd.ms-excel", "选择" + bllSub.Details(c => c.SubID == subID).FirstOrDefault().SubName + "此课程的学生信息.xls")); }