public override List<TestAssessmentHeaderCollection> GetHeader(string studentFile) { // Open Excel Workbook. var filename = string.Empty; var excelApp = new Excel.Application(); var tmp = excelApp.Workbooks; var excelWorkbook = tmp.Open(@studentFile, Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excelApp.Visible = true; excelApp.DisplayAlerts = false; //String activeworksheet = "Accepted Test Indicies"; var excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets.Item[1]; excelWorksheet.Select(true); excelWorksheet.Unprotect(); excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable; var range = excelWorksheet.UsedRange; excelWorksheet.Cells[1, 1].EntireColumn.ColumnWidth = 15; excelWorksheet.Cells[1, 3].EntireColumn.ColumnWidth = 20; /* *Capture Student fullname from Excel file and then get their student number form the data store. * If student if no number is return then they does not exist therefore add the student fullname to the datastore. */ List<TestAssessmentHeaderCollection> headerAttribute=null; IEnumerateExcelTestAssessmentData processStudentAssessmentData = new AssessmentTestDataEnumerator(); headerAttribute = processStudentAssessmentData.EnumerateHeaderData(range); /*Close Excel Workbook*/ excelWorkbook.Close(0); excelApp.Application.Quit(); GC.Collect(); GC.WaitForPendingFinalizers(); Marshal.ReleaseComObject(tmp); Marshal.ReleaseComObject(excelWorksheet); Marshal.ReleaseComObject(excelWorkbook); Marshal.ReleaseComObject(excelApp); return headerAttribute; }
public override List<TestAssessmentMeasurmentCollection> GetTestMeasures(string studentFile) { // Open Excel Workbook. String filename = string.Empty; Excel.Application excelApp = new Excel.Application(); Excel.Workbooks tmp = excelApp.Workbooks; var excelWorkbook = tmp.Open(@studentFile, Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excelApp.Visible = true; excelApp.DisplayAlerts = false; //String activeworksheet = "Accepted Test Indicies"; var excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets.Item[1]; excelWorksheet.Select(true); excelWorksheet.Unprotect(); excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable; var range = excelWorksheet.UsedRange; excelWorksheet.Cells[1, 1].EntireColumn.ColumnWidth = 15; excelWorksheet.Cells[1, 3].EntireColumn.ColumnWidth = 20; /* *Capture Student fullname from Excel file and then get their student number form the data store. * If student if no number is return then they does not exist therefore add the student fullname to the datastore. */ String fullname=""; var range1 = range.Cells[2, 2] as Excel.Range; if (range1 != null) fullname = Convert.ToString(range1.Value2); IStudentProfile getStudentAttribute = new GetStudentID(); int studentNumber=0; studentNumber=getStudentAttribute.StudentID(fullname); /*Parse Student Assessment Data from Excel Open Excel Document*/ IEnumerateExcelTestAssessmentData processStudentAssessmentData = new AssessmentTestDataEnumerator(); var testAttribute = processStudentAssessmentData.EnumerateAllTestData(studentNumber.ToString(), range); /*Close Excel Workbook*/ excelWorkbook.Close(0); excelApp.Application.Quit(); GC.Collect(); GC.WaitForPendingFinalizers(); Marshal.ReleaseComObject(tmp); Marshal.ReleaseComObject(excelWorksheet); Marshal.ReleaseComObject(excelWorkbook); Marshal.ReleaseComObject(excelApp); return testAttribute; }