public override Student StudentParser(string[] tokens) { if (tokens.Length < dataHeadersCount) { return(null); } try { var student = new XcelStudent() { ID = int.Parse(tokens[0]), FirstName = tokens[1], LastName = tokens[2], Email = tokens[3], Gender = (Gender)Enum.Parse(typeof(Gender), tokens[4], true), StudentType = (StudentType)Enum.Parse(typeof(StudentType), tokens[5], true), ExamResult = int.Parse(tokens[6]), HomeworksSent = int.Parse(tokens[7]), HomeworksEvaluated = int.Parse(tokens[8]), Teamwork = double.Parse(tokens[9]), Attendance = int.Parse(tokens[10]), Bonus = double.Parse(tokens[11]) }; return(student); } catch (ArgumentException) { return(null); } }
static void Main() { helper.ConsoleMio.Setup(); helper.ConsoleMio.PrintHeading("LINQ to Excel "); var studentsExtractor = new TextDocumentParser(); IList <XcelStudent> students = studentsExtractor.Genereate(1000).Cast <XcelStudent>().ToList(); var sheet = new Worksheet("Online Students"); string[] sheetHeader = studentsExtractor.HeaderLine; for (int i = 0; i < sheetHeader.Length; i++) { sheet.Cells[0, i] = new Cell(sheetHeader[i]); } // Add the result filed in the end sheet.Cells[0, sheetHeader.Length] = new Cell("Result"); helper.ConsoleMio.PrintColorText("Proccessing information...\n\n", ConsoleColor.DarkCyan); var onlineStudents = students .Where(student => student.StudentType == StudentType.Online) .OrderByDescending(student => student.CalculateResult()) .ToArray(); for (int i = 0; i < onlineStudents.Length; i++) { XcelStudent student = onlineStudents[i]; AddStudentDataToSheet(sheet, i + 1, student); } var workbook = new Workbook(); workbook.Worksheets.Add(sheet); helper.ConsoleMio.PrintColorText( "Query Completed\n", ConsoleColor.Green); string saveLocation = helper.SelectSaveLocation("Xcel Files|*.xls"); workbook.Save(saveLocation); helper.ConsoleMio.PrintColorText("Done", ConsoleColor.Green); helper.ConsoleMio.Restart(Main); }
private static void AddStudentDataToSheet(Worksheet sheet, int row, XcelStudent student) { sheet.Cells[row, 0] = new Cell(student.ID); sheet.Cells[row, 1] = new Cell(student.FirstName); sheet.Cells[row, 2] = new Cell(student.LastName); sheet.Cells[row, 3] = new Cell(student.Email); sheet.Cells[row, 4] = new Cell(student.Gender.ToString()); sheet.Cells[row, 5] = new Cell(student.StudentType.ToString()); sheet.Cells[row, 6] = new Cell(student.ExamResult); sheet.Cells[row, 7] = new Cell(student.HomeworksSent); sheet.Cells[row, 8] = new Cell(student.HomeworksEvaluated); sheet.Cells[row, 9] = new Cell(student.Teamwork); sheet.Cells[row, 10] = new Cell(student.Attendance); sheet.Cells[row, 11] = new Cell(student.Bonus); sheet.Cells[row, 12] = new Cell(student.CalculateResult()); }