public static string DumpDeps(Generator.Ctx parentCtx, Dictionary <string, XlsxR.Sheet> sheets, string[] stringTable, string[] forCells) { var sb = new StringBuilder(); foreach (var sheetCells in forCells.Select(SheetAndCell).GroupBy(sc => sc.Sheet)) { var sheetKey = (sheetCells.Key == null) ? sheets.Keys.First() : sheetCells.Key; var hlp = new DepsHelper() { already = new Dictionary <string, bool>(), sheet = sheets[sheetKey], stringTable = stringTable, parentCtx = parentCtx, }; foreach (var r in hlp.sheet.vals.Keys) { if (hlp.maxNdxColVal < r.col) { hlp.maxNdxColVal = r.col; } if (hlp.maxNdxRowVal < r.row) { hlp.maxNdxRowVal = r.row; } } var deps = new List <(CellRange cell, Expr expr)>(); foreach (var sc in sheetCells) { deps.AddRange(hlp.DumpDepsImpl(sc.Cell)); } deps.Sort((a, b) => CellRange.Compare(a.cell, b.cell)); var dict = deps.ToDictionary(d => d.cell.name, d => d.expr); var sorted = TopoSort.DoSort( deps.Select(d => d.cell.name), cell => dict[cell].EnumerateReferences() ); if (sb.Length > 0) { sb.AppendLine(); } sb.AppendLine($"//********** sheet: {sheetKey}"); foreach (var cell in sorted) { var info = hlp.GetCode(CellRange.FromName(cell), dict[cell]); if (!string.IsNullOrEmpty(info.rowComm)) { sb.AppendLine($"//row: {info.rowComm}"); } if (!string.IsNullOrEmpty(info.colComm)) { sb.AppendLine($"//col: {info.colComm}"); } sb.AppendLine(info.rngExpr); } } return(sb.ToString()); }