示例#1
0
 public static void Test4()
 {
     ExcelParseManager.ParseExcel("test_python.xlsx", false);
 }
示例#2
0
        public static void ParseExcel(string[] args)
        {
            if (args.Length >= 1)
            {
                var         path       = args[0];
                ParseConfig tempConfig = null;
                try
                {
                    tempConfig = ReadConfig(path);
                }
                catch (Exception e)
                {
                    Console.WriteLine("读取配置发生错误:path=" + path + ",error=" + e.Message);
                    return;
                }
                if (tempConfig == null)
                {
                    Console.WriteLine("读取配置" + path + "失败");
                    return;
                }
                GetInstance().config = tempConfig;
            }
            var           config = GetInstance().config;
            List <string> excels = new List <string>();

            if (args.Length >= 2)
            {
                //指定了excel
                excels.Add(args[1]);
            }
            else if (args.Length >= 1)
            {
                var dir = new DirectoryInfo(config.excelPath);
                foreach (var file in dir.GetFiles())
                {
                    if (file.Extension == ".xlsx" && !config.ignoreFiles.Contains(file.Name))
                    {
                        excels.Add(file.FullName);
                    }
                }
            }
            else
            {
                excels.Add("test_python_config.xlsx");
            }
            //第一步:生成proto数据
            foreach (var fileName in excels)
            {
                if (!ExcelParseManager.ParseExcel(fileName, true))
                {
                    Console.WriteLine("parse excel proto failed: " + fileName);
                    return;
                }
                else
                {
                    Console.WriteLine("parse excel proto sucess: " + fileName);
                }
            }
            //第二步:生成proto文件
            if (!ParseManager.GetInstance().GenerateProto())
            {
                Console.WriteLine("生成proto文件失败");
                return;
            }
            //第三步:解析数据
            foreach (var fileName in excels)
            {
                if (!ExcelParseManager.ParseExcel(fileName, false))
                {
                    Console.WriteLine("parse excel data failed: " + fileName);
                    return;
                }
                else
                {
                    Console.WriteLine("parse excel data sucess: " + fileName);
                }
            }
        }