private Word.Document BuildRequirementsDoc(Excel.Workbook workbook, out List<Requirement> requirements) { Word.Document doc = CreateWordDocument(); doc.Activate(); Excel.Worksheet rqmntsWorksheet = workbook.Worksheets["SRS"]; Excel.Range usedRange = rqmntsWorksheet.UsedRange; requirements = new List<Requirement>(); // The first row (i == 1) is reserved for headings, so skip it. for (int i = 2; i < usedRange.Rows.Count; i++) { var row = usedRange.Rows[i]; var rqmnt = ExcelRowToRequirement(row); if (rqmnt.Id != null) { requirements.Add(rqmnt); } } // Categorise requirements by their functional mappings (e.g. Sensing and Environment) var functions = requirements.Select(x => x.Function).Distinct(); foreach (var function in functions) { // Categorise requirements by their Type (e.g. Functional, Behavioural) var requirementsByType = from requirement in requirements where requirement.Function == function group requirement by requirement.Type into typesGroup orderby typesGroup.Key select typesGroup; Word.Range rng = doc.Bookmarks[EndOfDoc].Range; WriteParaText(function, rng, doc); foreach (var reqGroup in requirementsByType) { rng = doc.Bookmarks[EndOfDoc].Range; WriteParaText(reqGroup.Key, rng, doc); foreach (var rqmnt in reqGroup) { try { Word.Table table = RequirementToWordTable(rqmnt, doc.Bookmarks[EndOfDoc].Range, doc); rng = doc.Bookmarks[EndOfDoc].Range; rng.InsertParagraphAfter(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } } } return doc; }
private Requirement ExcelRowToRequirement(Excel.Range excelRow) { var r = new Requirement(); r.Id = excelRow.Cells[Missing, "A"].Value as string; r.Description = excelRow.Cells[Missing, "B"].Value as string; r.Function = excelRow.Cells[Missing, "C"].Value as string; r.Type = excelRow.Cells[Missing, "D"].Value as string; r.Classification = excelRow.Cells[Missing, "E"].Value as string; r.Rationale = excelRow.Cells[Missing, "F"].Value as string; r.Dependencies = excelRow.Cells[Missing, "G"].Value as string; r.DateCreated = excelRow.Cells[Missing, "H"].Value as string; r.ChangeHistory = excelRow.Cells[Missing, "I"].Value as string; r.Traceability = excelRow.Cells[Missing, "J"].Value as string; return r; }
private Excel.Range FindInWorksheet(string searchText, Excel.Worksheet pssuWorksheet) { return pssuWorksheet.Cells.Find( searchText, Missing, Missing, Missing, Missing, Excel.XlSearchDirection.xlNext, Missing, Missing, Missing); }
private void BuildTraceMatrix(Excel.Workbook workbook, List<Requirement> requirements) { Excel.Worksheet urdSheet = workbook.Worksheets["URD"]; Excel.Worksheet traceSheet = workbook.Worksheets["Matrix"]; var urdColMap = new Dictionary<string, int>(); for (int i = 2; i <= urdSheet.UsedRange.Rows.Count; i++) { Excel.Range row = urdSheet.UsedRange.Rows[i]; var cellValue = row.Cells[Missing, 1].Value as string; if (cellValue != null) { urdColMap.Add(cellValue, i); } } var srsTraceMap = new Dictionary<string, string[]>(); foreach(var r in requirements) { var tracedList = new string [] { "" }; if (r.Traceability != null) { tracedList = r.Traceability.Split(','); } for (int i = 0; i < tracedList.Length; i++) { tracedList[i] = tracedList[i].Trim(); } srsTraceMap.Add(r.Id, tracedList); } // URD Column headings foreach (var pair in urdColMap) { traceSheet.Cells[1, pair.Value].Value = pair.Key; } int rowIdx = 2; // Fill out the table foreach (var pair in srsTraceMap) { // SRS Row label traceSheet.Cells[rowIdx, 1].Value = pair.Key; foreach (var tracedUrd in pair.Value) { if (urdColMap.ContainsKey(tracedUrd)) { traceSheet.Cells[rowIdx, urdColMap[tracedUrd]].Value = "X"; } } rowIdx++; } }