Example #1
0
        GenerateGroupData(ISheet sheet, int beginRow, int endRow)
        {
            // WriteLine("生成分组映射表");
            var map = new Dictionary <string, Group>();

            for (var index = beginRow - 1; index < endRow; index++)
            {
                var   xzqh  = sheet.Cell(index, "A").Value();
                Match match = null;
                foreach (var regex in Xzqh.regex)
                {
                    match = Regex.Match(xzqh, regex);
                    if (match.Success)
                    {
                        break;
                    }
                }
                if (match == null || !match.Success)
                {
                    throw new ApplicationException($"未匹配行政区划: {xzqh}");
                }
                else
                {
                    var xzj = match.Groups[2].Value;
                    var csq = match.Groups[3].Value;
                    if (!map.ContainsKey(xzj))
                    {
                        map[xzj] = new Group
                        {
                            Total = 0,
                            Data  = new Dictionary <string, List <int> >()
                        }
                    }
                    ;

                    if (!map[xzj].Data.ContainsKey(csq))
                    {
                        map[xzj].Data[csq] = new List <int> {
                            index
                        };
                        map[xzj].Total += 1;
                    }
                    else
                    {
                        map[xzj].Data[csq].Add(index);
                        map[xzj].Total += 1;
                    }
                }
            }
            return(map);
        }
    }