示例#1
0
        /// <summary>
        /// 解析Excel文档
        /// </summary>
        public void DoParseTest(string outDllFileName)
        {
            var sheetNames = GetSheets();
            Dictionary <string, List <ExcelHeader> > headerDic = new Dictionary <string, List <ExcelHeader> >();
            Dictionary <string, string> classDic = new Dictionary <string, string>();

            foreach (var sheetName in sheetNames)
            {
                try
                {
                    var headers = GetHeader(sheetName);
                    headerDic[sheetName] = headers;

                    GenarateCSharpCode gc = new GenarateCSharpCode();
                    var classText         = gc.GenarateClass(sheetName, headers);
                    classDic.Add(sheetName, classText);
                    var indexValues = SaveXMLData(sheetName, headers, sheetName + ".xml", sheetName + ".json");

                    if (sheetName == "SystemConfig")
                    {
                        var enumText = gc.GenarateEnum(sheetName, indexValues);
                        classDic.Add(nameof(Enum) + sheetName, enumText);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Sheet [" + sheetName + "] header invalid");
                }
            }

            var assemblyText = Resource1.ClassTemplete;

            assemblyText += "\r\n{\r\n";
            assemblyText += Resource1.ScriptBase;
            assemblyText += "\r\n\r\n";

            foreach (var classTextkv in classDic)
            {
                assemblyText += classTextkv.Value;
                assemblyText += "\r\n";
            }

            assemblyText += "\r\n}\r\n";

            DynamicCompile compile = new DynamicCompile();
            var            asm     = compile.Compile(assemblyText, outDllFileName);

            //var type = asm.GetType("ExcelTables." + sheetName);
            //SaveXMLData(sheetName, headers, type, sheetName + ".xml");
        }
示例#2
0
        public void DoParse(ref Dictionary <string, string> classDic, string xmlSavePath, string jsonSavePath)
        {
            var cacheFiles  = GetFileCaches();
            var currentFile = GetCurrentFile();
            var sheetNames  = GetSheets();
            Dictionary <string, List <ExcelHeader> > headerDic = new Dictionary <string, List <ExcelHeader> >();

            foreach (var sheetName in sheetNames)
            {
                try
                {
                    var headers = GetHeader(sheetName);
                    headerDic[sheetName] = headers;

                    GenarateCSharpCode gc = new GenarateCSharpCode();
                    var classText         = gc.GenarateClass(sheetName, headers);
                    classDic.Add(sheetName, classText);

                    if (cacheFiles.ContainsKey(FileName) &&
                        cacheFiles[FileName].Hash == currentFile.Hash &&
                        sheetName != SysConfigSheetName)
                    {
                        continue;
                    }

                    var indexValues = SaveXMLData(sheetName, headers,
                                                  xmlSavePath.Trim('\\') + "\\" + sheetName + ".xml",
                                                  jsonSavePath.Trim('\\') + "\\" + sheetName + ".json");
                    if (sheetName == SysConfigSheetName)
                    {
                        var enumText = gc.GenarateEnum(sheetName, indexValues);
                        classDic.Add(nameof(Enum) + sheetName, enumText);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Sheet [" + sheetName + "] header invalid");
                }
            }

            cacheFiles[FileName] = currentFile;
            SaveCacheFile(cacheFiles);
        }