public FileResult Excel_NotRegisterStudents() { string path = Path.Combine(Server.MapPath("~/Content/Reports/Excel/"), "StudentTemplate.xlsx"); Microsoft_Excel _Excel = new Microsoft_Excel(path); _Excel.Open(1); int i = 1; foreach (var item in db.Tbl_Student.Where(a => a.Student_Info == false || a.Student_Form1 == false || a.Student_Form2 == false || a.Student_TakeTurn == false).OrderBy(a => a.Student_Code).ToList()) { _Excel.WriteToCell(i, 0, item.Student_Code); _Excel.WriteToCell(i, 1, item.Student_NationalCode); _Excel.WriteToCell(i, 2, item.Student_SIID.HasValue ? item.Tbl_StudentInfo.SI_Name : "نا معلوم"); _Excel.WriteToCell(i, 3, item.Student_SIID.HasValue ? item.Tbl_StudentInfo.SI_Family : "نا معلوم"); _Excel.WriteToCell(i, 4, item.Student_Info ? "تکمیل شده" : "تکمیل نشده"); _Excel.WriteToCell(i, 5, item.Student_Form1 ? "تکمیل شده" : "تکمیل نشده"); _Excel.WriteToCell(i, 6, item.Student_Form2 ? "تکمیل شده" : "تکمیل نشده"); _Excel.WriteToCell(i, 7, item.Student_TakeTurn ? "تکمیل شده" : "تکمیل نشده"); i++; } string SaveAsPath = Path.Combine(Server.MapPath("~/App_Data/Excel/"), string.Format("{0}.xlsx", Guid.NewGuid())); _Excel.SaveAs(SaveAsPath); _Excel.Close(); return(File(SaveAsPath, "*", string.Format("{0}.xlsx", "دانشجویان ثبت نام نشده"))); }
public FileResult Excel(int id) { var _TakeTurn = db.Tbl_TurnTimeSheet.Where(a => a.TTS_ID == id).SingleOrDefault().Tbl_TakeTurn; var _Student = _TakeTurn.Select(a => a.Tbl_Student).OrderBy(a => a.Student_Code).Select(a => new Model_StudentTakeTimeList { ID = a.Student_ID, Student_Code = a.Student_Code, Student_National = a.Student_NationalCode, Student_Name = a.Student_SIID.HasValue ? a.Tbl_StudentInfo.SI_Name : "نا معلوم", Student_Family = a.Student_SIID.HasValue ? a.Tbl_StudentInfo.SI_Family : "نا معلوم", per = false, }).ToList(); string path = Path.Combine(Server.MapPath("~/Content/Reports/Excel/"), "TurnReportTemplate.xlsx"); Microsoft_Excel _Excel = new Microsoft_Excel(path); _Excel.Open(1); int i = 1; foreach (var item in _Student) { _Excel.WriteToCell(i, 0, item.Student_Code); _Excel.WriteToCell(i, 1, item.Student_National); _Excel.WriteToCell(i, 2, item.Student_Name); _Excel.WriteToCell(i, 3, item.Student_Family); i++; } string SaveAsPath = Path.Combine(Server.MapPath("~/App_Data/Excel/"), string.Format("{0}.xlsx", Guid.NewGuid())); _Excel.SaveAs(SaveAsPath); _Excel.Close(); string filename = _TakeTurn.FirstOrDefault().Tbl_TurnTimeSheet.TTS_Name; return(File(SaveAsPath, "*", string.Format("{0}.xlsx", filename))); }