private static int FillSyntaxToExcel(dynamic worksheet, int rowcount, IDL2PgmStruct pgm) { foreach (var section in pgm.SectionList) { if (section.SyntaxSetList.Count != 0) { foreach (var syntaxset in section.SyntaxSetList) { if (syntaxset.BranchNo == 0) continue; worksheet.Cells(rowcount, 1).Value = pgm.PgmID; worksheet.Cells(rowcount, 2).Value = section.SectionName; worksheet.Cells(rowcount, 3).Value = syntaxset.SyntaxSetType + (string.IsNullOrEmpty(syntaxset.ExtendInfo) ? String.Empty : "@" + syntaxset.ExtendInfo); int colcount = 5; HashSet<String> TestItem = new HashSet<string>(); foreach (var syntax in syntaxset.SyntaxList) { if (syntax.Cond != null) { foreach (var item in syntax.Cond.TestItemLst) { if (!TestItem.Contains(item)) { TestItem.Add(item); }; } } if (syntax.SyntaxType != "CASE") { //第一个CASE不需要出现在列表中 worksheet.Cells(rowcount, colcount).Value = syntax.SyntaxType; colcount++; worksheet.Cells(rowcount, colcount).Value = syntax.LineNo; colcount++; worksheet.Cells(rowcount, colcount).Value = String.IsNullOrEmpty(syntax.ExtendInfo) ? "" : syntax.ExtendInfo.Trim(); colcount++; worksheet.Cells(rowcount, colcount).Value = String.IsNullOrEmpty(syntax.Result) ? "" : syntax.Result.Trim(); colcount++; } } if (TestItem.Count > 0) { String strTestItem = String.Empty; foreach (var item in TestItem) { strTestItem += "[ " + item + " ]、"; } strTestItem = strTestItem.Substring(0, strTestItem.Length - 1); switch (syntaxset.SyntaxSetType) { case "IF": strTestItem += " の条件分岐判定"; break; case "CASE": strTestItem += " の多条件分岐判定"; break; case "FOR": case "LOOP": case "WHILE": case "REPEAT": strTestItem += " のループ処理の判定"; break; default: break; } worksheet.Cells(rowcount, 4).Value = strTestItem; } else { if (syntaxset.SyntaxSetType == "CASE") { worksheet.Cells(rowcount, 4).Value = "[試験条件不明]"; } } rowcount++; } } else { worksheet.Cells(rowcount, 1).Value = pgm.PgmID; worksheet.Cells(rowcount, 2).Value = section.SectionName; rowcount++; } } return rowcount; }
private void btnGetBranch_Click(object sender, EventArgs e) { if (DarumaDB.CollectionExists("PmgStructure")) { DarumaDB.DropCollection("PmgStructure"); } MongoCollection DarumaCol = DarumaDB.GetCollection("PmgStructure"); dynamic excelObj = Microsoft.VisualBasic.Interaction.CreateObject("Excel.Application"); excelObj.Visible = true; dynamic workbook = excelObj.Workbooks.Open(@"C:\Daruma\Tools\PgmList.xlsx"); dynamic worksheet = workbook.Sheets(3); worksheet.Select(); worksheet.Name = "SyntaxSet"; int rowcount = 1; int pgmcount = 0; if (Directory.Exists(idl2MainFolder)) { foreach (String filename in Directory.GetFiles(idl2MainFolder)) { IDL2PgmStruct pgm = new IDL2PgmStruct(); pgm.Analyze(filename); pgm.PgmID = new FileInfo(filename).Name.TrimEnd(".TXT".ToCharArray()); DarumaCol.Insert<IDL2PgmStruct>(pgm); worksheet.Cells(rowcount, 1).Value = pgm.PgmID; rowcount++; rowcount = FillSyntaxToExcel(worksheet, rowcount, pgm); pgmcount++; if (pgmcount % 100 == 0) { workbook.Save(); } } } MessageBox.Show("Complete!!PgmCount:" + pgmcount); }