Exemplo n.º 1
0
        public static string CheckExcel(string path)
        {
            StringBuilder sb = new StringBuilder();
            //解析规则的xml文件

            //check每一个cell
            RuleModel   rules  = GetRule();
            ExcelHelper helper = null;

            try
            {
                helper = new ExcelHelper(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                sb.AppendLine("检查失败!");
                return(sb.ToString());
            }


            foreach (Rule rule in rules.Rules)
            {
                switch (rule.Type)
                {
                case "String":
                    foreach (var l in rule.Locations)
                    {
                        string sheetName = l.loc.Split(',')[0];
                        if (l.loc.Split(',')[1].Contains("+"))
                        {
                            int startRowNum = Convert.ToInt32(l.loc.Split(',')[1].Replace("+", "")) - 1;
                            int lastRowNum  = helper.GetSheetRowCount(sheetName);
                            for (int i = startRowNum; i < lastRowNum; i++)
                            {
                                sb.AppendLine(CheckStringType(helper, rule.IsNull, l, i));
                            }
                        }
                        else
                        {
                            int rowNum = Convert.ToInt32(l.loc.Split(',')[1]) - 1;
                            sb.AppendLine(CheckStringType(helper, rule.IsNull, l, rowNum));
                        }
                    }
                    break;

                case "Date":
                    break;
                }
            }
            if (string.IsNullOrEmpty(sb.ToString()))
            {
                sb.Append("文件内容正确!");
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        private static RuleModel GetRule()
        {
            RuleModel result = new RuleModel();

            return(result);
        }