public static void ExportSemester(StudyYear year, SemesterType semester) { string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Templates\SemesterTemplate.xltx"); Dictionary <string, int> counts = new Dictionary <string, int>() { { "ФИТ", 0 }, { "МСФ", 0 }, { "ИДПО", 0 }, { "МАГ", 0 } }; List <DisciplineWorkload> workloads = _service.GetAllDisciplineWorkloadsByYearAndSemesterType(year.Year, semester); workloads = workloads.OrderBy(w => w.Semester.Number).ToList(); if (workloads.Count > 0) { Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application(); Workbook ObjWorkBook; Worksheet ObjWorkSheet; ObjWorkBook = ObjExcel.Workbooks.Add(path); ObjWorkSheet = (Worksheet)ObjWorkBook.Sheets[1]; ObjWorkBook.Title = string.Format("Отчет {0} семестр({1} / {2})", semester.ToDescriptionString(), year.Year, year.Year + 1); ObjWorkSheet.Cells[3, 1] = string.Format("экзаменационной сессии за {0} семестр {1} / {2} учебного года", semester.ToDescriptionString(), year.Year, year.Year + 1); foreach (var w in workloads) { int rowCounter = SemesterExport.Default.FITStartRow; if (w.DisciplineYear.Discipline.TypeOfDiscipline == DisciplineType.SPECIAL) { rowCounter++; continue; } Group group = w.Group; int cource = year.Year - group.EntryYear + 1; Discipline discipline = w.DisciplineYear.Discipline; int countStud = group.CountOfStudents; int weeks = w.Semester.CountOfWeeks; int lec = w.DisciplineYear.CountOfLecture; int prac = w.DisciplineYear.CountOfPractice; int lab = w.DisciplineYear.CountOfLabs; bool kr = w.DisciplineYear.HasKR; bool kp = w.DisciplineYear.HasKP; bool ekz = w.DisciplineYear.HasEx; bool zach = w.DisciplineYear.HasCR; float summ = WorkloadsCalculator.GetWorkloadCost(w); int index = 0; if (w.Group.StudyForm != StudyForm.FullTime) { rowCounter = counts["ФИТ"] + counts["ИДПО"] + counts["МСФ"] + SemesterExport.Default.IDPOStartRow; counts["ИДПО"]++; index = counts["ИДПО"]; } else if (w.Group.Speciality.Faculty.ShortName == "ФИТ") { if (w.Group.Qualification != Qualification.Magistracy) { rowCounter += counts["ФИТ"]; counts["ФИТ"]++; index = counts["ФИТ"]; } else { rowCounter = counts["ФИТ"] + counts["ИДПО"] + counts["МАГ"] + counts["МСФ"] + SemesterExport.Default.MAGStartRow; counts["МАГ"]++; index = counts["МАГ"]; } } else if (w.Group.Speciality.Faculty.ShortName == "МСФ") { rowCounter = counts["ФИТ"] + counts["МСФ"] + SemesterExport.Default.MSFStartRow; counts["МСФ"]++; index = counts["МСФ"]; } { Range line = (Range)ObjWorkSheet.Rows[rowCounter]; line.Insert(); ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.IndexColumn] = index; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.GroupColumn] = group.Speciality.Name; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.CourceColumn] = cource; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.DisciplineColumn] = w.DisciplineYear.Discipline.Name; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.DisciplineCostColumn] = summ; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.LecFactColumn] = lec * weeks; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.StudentsColumn] = countStud; ObjWorkSheet.Cells[rowCounter, SemesterExport.Default.DisciplineColumn].EntireRow.AutoFit(); //применить автовысоту } rowCounter++; } ObjExcel.Visible = true; ObjExcel.UserControl = true; } }