Exemple #1
0
        public static void GenerateFile(ExcelSheet sheet, Action callback = null)
        {
            if (ExcelExportOutSetting.IsCreateNew)
            {
                ExcelUtil.ResetDirectory(ExcelExportOutSetting.OutDataDir);
                ExcelUtil.ResetDirectory(ExcelExportOutSetting.OutClassDir);
            }
            else
            {
                ExcelUtil.CheckCreateDirectory(ExcelExportOutSetting.OutDataDir);
                ExcelUtil.CheckCreateDirectory(ExcelExportOutSetting.OutClassDir);
            }

            CreateConfigClass(sheet);
            CreateConfigData(sheet);
            callback?.Invoke();
        }
Exemple #2
0
        public static void CreateLangXml(ExcelSheet sheet)
        {
            if (ExcelExportOutSetting.IsCreateNew)
            {
                ExcelUtil.ResetDirectory(ExcelExportOutSetting.OutLanguageDir);
            }
            else
            {
                ExcelUtil.CheckCreateDirectory(ExcelExportOutSetting.OutLanguageDir);
            }

            for (int i = 1; i < sheet.Fields.Count; i++)
            {
                ExcelSheetTableField excelSheetTableField = sheet.Fields[i];
                CreatXml(excelSheetTableField.Name, sheet);
            }
        }
Exemple #3
0
        private static void CreateConfigClass(ExcelSheet sheet)
        {
            string        firstField = null;
            string        savePath   = $"{ExcelExportOutSetting.OutClassDir}/{sheet.ConfigName}.cs";
            StringBuilder fieldStrs  = new StringBuilder();

            fieldStrs.AppendLine("//------------------------------------------------------------");
            fieldStrs.AppendLine("// 此文件由工具自动生成,请勿直接修改。");
            fieldStrs.AppendLine("// 生成时间:" + DateTime.Now);
            fieldStrs.AppendLine("//------------------------------------------------------------");
            fieldStrs.AppendLine();
            fieldStrs.AppendLine("using System;");
            fieldStrs.AppendLine("using System.Collections.Generic;");
            fieldStrs.AppendLine();
            fieldStrs.AppendLine("namespace " + ExcelExportOutSetting.NameSpace);
            {
                fieldStrs.AppendLine("{");
                fieldStrs.AppendLine($"\t/// <summary>{sheet.NameDes}</summary>");
                fieldStrs.AppendLine($"\tpublic class {sheet.ConfigName} : BaseConfig");
                {
                    fieldStrs.AppendLine("\t{");
                    fieldStrs.AppendLine("\t\t/// <summary>唯一ID</summary>");
                    if (!sheet.IsVert)
                    {
                        fieldStrs.AppendLine("\t\tpublic override object UniqueID => id;");
                    }
                    else
                    {
                        fieldStrs.AppendLine($"\t\tpublic override object UniqueID => {sheet.Fields[0].Name};");
                    }


                    foreach (ExcelSheetTableField filed in sheet.Fields)
                    {
                        bool flag      = filed.IsInterface;
                        var  filedProp = flag ? " { get; set; }" : ";";

                        bool flag2 = firstField == null;
                        if (flag2)
                        {
                            firstField = filed.Name;
                        }

                        fieldStrs.AppendLine();
                        fieldStrs.AppendLine("\t\t/// <summary>");
                        string[] desStrings = filed.Des.Split('\n');
                        foreach (var variable in desStrings)
                        {
                            fieldStrs.AppendLine($"\t\t/// {variable}");
                        }
                        fieldStrs.AppendLine("\t\t/// </summary>");
                        fieldStrs.AppendLine(
                            $"\t\tpublic {ExcelUtil.GetCSStringType(filed.Type, false)} {filed.Name}{filedProp}");
                    }

                    fieldStrs.AppendLine("\t}");
                }
                fieldStrs.AppendLine("}");
            }
            ExcelUtil.SaveFile(savePath, fieldStrs.ToString(), true, true);
        }
Exemple #4
0
        public static void CreateConfigMgr(List <ExcelSheet> configList, Action callback = null)
        {
            ExcelUtil.CheckCreateDirectory(ExcelExportOutSetting.OutConfigMgrDir);
            string savePath = $"{ExcelExportOutSetting.OutConfigMgrDir}/ConfigMgr.cs";

            StringBuilder dicStrs_V = new StringBuilder();
            StringBuilder funStrs_H = new StringBuilder();
            StringBuilder funStrs_V = new StringBuilder();

            foreach (var sheet in configList)
            {
                if (sheet.Name.Equals("Language"))
                {
                    continue;
                }
                if (sheet.IsVert)
                {
                    dicStrs_V.AppendLine($"\t\t/// <summary> {sheet.NameDes} </summary>");
                    dicStrs_V.AppendLine($"\t\tpublic {sheet.ConfigName} {ExcelUtil.ToFirstLower(sheet.ConfigName)};");
                    funStrs_V.AppendLine(
                        $"\t\t\t{ExcelUtil.ToFirstLower(sheet.ConfigName)} = await readConfigV<{sheet.ConfigName}>();");
                }
                else
                {
                    funStrs_H.AppendLine($"\t\t\treadConfig<{sheet.Name}Config>().Run();//{sheet.NameDes}");
                }
            }

            StringBuilder fieldStrs = new StringBuilder();

            fieldStrs.AppendLine("//------------------------------------------------------------");
            fieldStrs.AppendLine("// 此文件由工具自动生成,请勿直接修改。");
            fieldStrs.AppendLine("// 生成时间:" + DateTime.Now);
            fieldStrs.AppendLine("//------------------------------------------------------------");
            fieldStrs.AppendLine();
            fieldStrs.AppendLine("using System.Collections.Generic;");
            fieldStrs.AppendLine("using Fuse.Tasks;");
            fieldStrs.AppendLine();
            fieldStrs.AppendLine("namespace " + ExcelExportOutSetting.NameSpace);
            fieldStrs.AppendLine("{");
            {
                fieldStrs.AppendLine("\tpublic partial class ConfigMgr");
                fieldStrs.AppendLine("\t{");
                {
                    fieldStrs.AppendLine(dicStrs_V.ToString());
                    fieldStrs.AppendLine();

                    fieldStrs.AppendLine("\t\tprivate void LoadAllConfig()");
                    fieldStrs.AppendLine("\t\t{");
                    {
                        fieldStrs.AppendLine(funStrs_H.ToString());
                        fieldStrs.AppendLine();
                        fieldStrs.AppendLine("\t\t\t//读取竖表配置");
                        fieldStrs.AppendLine("\t\t\tLoadAllConfigV().Run();");
                        fieldStrs.AppendLine();
                        fieldStrs.AppendLine("\t\t\tCustomRead();");
                    }
                    fieldStrs.AppendLine("\t\t}");
                    fieldStrs.AppendLine("\t\t/// <summary>读取竖表配置</summary>");
                    fieldStrs.AppendLine("\t\tprivate async CTask LoadAllConfigV()");
                    fieldStrs.AppendLine("\t\t{");
                    {
                        fieldStrs.AppendLine(funStrs_V.ToString());
                    }
                    fieldStrs.AppendLine("\t\t}");
                }
                fieldStrs.AppendLine("\t}");
            }
            fieldStrs.AppendLine("}");
            ExcelUtil.SaveFile(savePath, fieldStrs.ToString(), true, true);

            callback?.Invoke();
        }
Exemple #5
0
        private static void addSheetTableRow(ExcelSheet sheet, DataTable dtSource)
        {
            bool isVert = sheet.IsVert;

            if (isVert)
            {
                DataRow expRow = sheet.Table.NewRow();
                for (int c = 0; c < sheet.Fields.Count; c++)
                {
                    ExcelSheetTableField field = sheet.Fields[c];
                    bool flag = field.Export == string.Empty;
                    if (!flag)
                    {
                        object val   = ExcelUtil.GetObjectValue(field.Type, field.Value, 1);
                        bool   flag2 = val == null;
                        if (flag2)
                        {
                            Debug.LogWarning(sheet.FullName + "表," + field.Name + "字段" + field.Type +
                                             "类型未写转换规则,已转换为string类型");
                            val = string.Empty;
                        }

                        expRow[c] = val;
                    }
                }

                sheet.Table.Rows.Add(expRow);
            }
            else
            {
                for (int i = 4; i < dtSource.Rows.Count; i++)
                {
                    DataRow expRow2 = sheet.Table.NewRow();
                    bool    flag3   = string.IsNullOrEmpty(dtSource.Rows[i][0].ToString());
                    if (!flag3)
                    {
                        int cellIndex = 0;
                        for (int f = 0; f < sheet.Fields.Count; f++)
                        {
                            ExcelSheetTableField field2 = sheet.Fields[f];
                            bool flag4 = field2.Export == string.Empty;
                            if (flag4)
                            {
                                cellIndex++;
                            }
                            else
                            {
                                string cellVal = dtSource.Rows[i][cellIndex].ToString();
                                cellIndex++;
                                object val2  = ExcelUtil.GetObjectValue(field2.Type, cellVal, field2.FieldCount);
                                bool   flag5 = val2 == null;
                                if (flag5)
                                {
                                    Debug.LogWarning(sheet.FullName + "表," + field2.Name + "字段" + field2.Type +
                                                     "类型未写转换规则,已转换为string类型");
                                    val2 = string.Empty;
                                }

                                bool flag6 = field2.FieldCount > 1;
                                if (flag6)
                                {
                                    for (int j = 1; j < field2.FieldCount; j++)
                                    {
                                        ExcelUtil.AddListValue(field2.Type, dtSource.Rows[i][cellIndex].ToString(),
                                                               ref val2);
                                        cellIndex++;
                                    }
                                }
                                expRow2[f] = val2;
                            }
                        }

                        sheet.Table.Rows.Add(expRow2);
                    }
                }
            }
        }
Exemple #6
0
        private static bool setSheetTable(ExcelSheet sheet, DataTable dtSource)
        {
            bool flag = dtSource.Columns.Count > 100;
            bool result;

            if (flag)
            {
                Debug.LogError(sheet.FullName + "表列数太多,请检查表格式");
                result = false;
            }
            else
            {
                bool isVert = sheet.IsVert;
                if (isVert)
                {
                    bool flag2 = dtSource.Rows.Count < 1 && dtSource.Columns.Count < 5;
                    if (flag2)
                    {
                        Debug.LogError(sheet.FullName + "表列数不对");
                        result = false;
                    }
                    else
                    {
                        int emptyRow = 0;
                        for (int i = 1; i < dtSource.Rows.Count; i++)
                        {
                            bool flag3 = dtSource.Rows[i][0].ToString() == string.Empty;
                            if (flag3)
                            {
                                emptyRow++;
                                bool flag4 = emptyRow > 3;
                                if (flag4)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                emptyRow = 0;
                                ExcelSheetTableField field = new ExcelSheetTableField();
                                field.Name        = dtSource.Rows[i][0].ToString();
                                field.Export      = dtSource.Rows[i][1].ToString();
                                field.Type        = dtSource.Rows[i][2].ToString().ToLower();
                                field.Value       = dtSource.Rows[i][3].ToString();
                                field.Des         = dtSource.Rows[i][4].ToString();
                                field.IsInterface = (field.Export.IndexOf('I') != -1);
                                sheet.Table.Columns.Add(field.Name, ExcelUtil.GetStringType(field.Type));
                                sheet.Fields.Add(field);
                            }
                        }

                        sheet.Export    = dtSource.Rows[1][1].ToString().ToUpper();
                        sheet.IsEncrypt = (sheet.Export.IndexOf('@') != -1);
                        result          = true;
                    }
                }
                else
                {
                    bool flag5 = dtSource.Rows.Count < 4 && dtSource.Columns.Count < 2;
                    if (flag5)
                    {
                        Debug.LogError(sheet.FullName + "表列数不对");
                        result = false;
                    }
                    else
                    {
                        ExcelSheetTableField field2 = null;
                        for (int j = 0; j < dtSource.Columns.Count; j++)
                        {
                            string[] arrInfo = dtSource.Rows[3][j].ToString().Split(new char[]
                            {
                                '#'
                            });
                            string fieldName = arrInfo[0];
                            bool   flag6     = fieldName == string.Empty;
                            if (flag6)
                            {
                                break;
                            }

                            bool flag7 = field2 == null || field2.Name != fieldName;
                            if (flag7)
                            {
                                field2             = new ExcelSheetTableField();
                                field2.Des         = dtSource.Rows[0][j].ToString();
                                field2.Export      = dtSource.Rows[1][j].ToString();
                                field2.Type        = dtSource.Rows[2][j].ToString().ToLower();
                                field2.Name        = fieldName;
                                field2.IsInterface = (field2.Export.IndexOf('I') != -1);
                                field2.FieldCount  = 1;
                                sheet.Fields.Add(field2);
                                sheet.Table.Columns.Add(field2.Name, ExcelUtil.GetStringType(field2.Type));
                            }
                            else
                            {
                                ExcelSheetTableField excelSheetTableField = field2;
                                excelSheetTableField.Des =
                                    excelSheetTableField.Des + "\n" + dtSource.Rows[0][j].ToString();
                                field2.FieldCount++;
                            }
                        }

                        sheet.Export    = dtSource.Rows[1][0].ToString().ToUpper();
                        sheet.IsEncrypt = (sheet.Export.IndexOf('@') != -1);
                        result          = true;
                    }
                }
            }

            return(result);
        }
Exemple #7
0
        public static Dictionary <string, ExcelSheet> GetExcleSheet(List <string[]> fils)
        {
            Dictionary <string, ExcelSheet> dicSheet = new Dictionary <string, ExcelSheet>();

            foreach (string[] file in fils)
            {
                DataSet ds = ExcelUtil.ReadExcelSheetData(file[1]);
                foreach (object obj in ds.Tables)
                {
                    DataTable dt         = (DataTable)obj;
                    string[]  sheeltInfo = dt.TableName.Split(new char[]
                    {
                        '#'
                    });
                    bool flag2 = sheeltInfo.Length < 2;
                    if (!flag2)
                    {
                        string[] sheeltTypeInfo = sheeltInfo[0].Split(new char[]
                        {
                            '_'
                        });
                        string tableName = ExcelUtil.ToFirstUpper(sheeltTypeInfo[0]);
                        bool   isVert    = false;
                        bool   flag3     = sheeltTypeInfo.Length > 1;
                        if (flag3)
                        {
                            bool flag4 = sheeltTypeInfo[1].ToLower() == "v";
                            if (flag4)
                            {
                                isVert = true;
                            }
                        }

                        ExcelSheet sheet;
                        bool       flag5 = !dicSheet.TryGetValue(tableName, out sheet);
                        if (flag5)
                        {
                            sheet         = new ExcelSheet();
                            sheet.Name    = tableName;
                            sheet.NameDes = sheeltInfo[1];
                            bool flag6 = sheeltInfo.Length > 2;
                            if (flag6)
                            {
                                sheet.Interface = sheeltInfo[2];
                            }

                            sheet.IsVert   = isVert;
                            sheet.FileName = file[0];
                            sheet.Table    = new DataTable();
                            bool flag7 = !ExcelExportParse.setSheetTable(sheet, dt);
                            if (flag7)
                            {
                                return(null);
                            }

                            dicSheet.Add(tableName, sheet);
                        }
                        else
                        {
                            bool isVert2 = sheet.IsVert;
                            if (isVert2)
                            {
                                Debug.LogError("表" + sheet.FullName + "是竖表结构,不能做分表");
                                return(null);
                            }

                            ExcelSheet nSheet = new ExcelSheet();
                            nSheet.Table = new DataTable();
                            nSheet.Name  = dt.TableName;
                            bool flag8 = !ExcelExportParse.setSheetTable(nSheet, dt);
                            if (flag8)
                            {
                                return(null);
                            }

                            bool flag9 = sheet.IsVert != isVert || !ExcelExportParse.checkSheetColumns(sheet, nSheet);
                            if (flag9)
                            {
                                Debug.LogError("表" + sheet.FullName + "定义的表结构不一至,请检查!!!!,目标表:" + dt.TableName);
                                return(null);
                            }
                        }

                        ExcelExportParse.addSheetTableRow(sheet, dt);
                    }
                }
            }

            return(dicSheet);
        }
Exemple #8
0
        // Token: 0x060000B0 RID: 176 RVA: 0x0000B1D8 File Offset: 0x000093D8
        public static object GetObjectValue(string type, string value, int fieldCount = 1)
        {
            bool isSetDef = fieldCount > 1;

            switch (type)
            {
            case "string":
                return(value);

            case "string[]":
                return(ExcelUtil.SplitToArr <string>(value, isSetDef, ';'));

            case "byte":
                byte.TryParse(value, out byte byteVal);
                return(byteVal);

            case "byte[]":
                return(ExcelUtil.SplitToArr <byte>(value, isSetDef, ';'));

            case "int":
                double.TryParse(value, out double floatV);
                return(Convert.ToInt32(floatV));

            case "int[]":
                return(ExcelUtil.SplitToArr <int>(value, isSetDef, ';'));

            case "long":
                long.TryParse(value, out long longVal);
                return(longVal);

            case "long[]":
                return(ExcelUtil.SplitToArr <long>(value, isSetDef, ';'));

            case "double":
                double.TryParse(value, out double doubleVal);
                return(doubleVal);

            case "double[]":
                return(ExcelUtil.SplitToArr <double>(value, isSetDef, ';'));

            case "float":
                float.TryParse(value, out float floatVal);
                return(floatVal);

            case "float[]":
                return(ExcelUtil.SplitToArr <float>(value, isSetDef, ';'));

            case "short":
                double.TryParse(value, out floatV);
                short shortVal = Convert.ToInt16(floatV);
                return(shortVal);

            case "short[]":
                return(ExcelUtil.SplitToArr <short>(value, isSetDef, ';'));

            case "bool":
                bool flag = value == "1";
                if (flag)
                {
                    return(true);
                }
                bool boolVal = false;
                bool.TryParse(value, out boolVal);
                return(boolVal);

            case "bool[]":
                return(ExcelUtil.SplitToArr <bool>(value, isSetDef, ';'));

            case "list<int[]>":
                return(SplitToItems(SplitToArr <string>(value, false, ';')));

            case "list<list<int[]>>":
                return(new List <List <int[]> >
                {
                    ExcelUtil.SplitToItems(ExcelUtil.SplitToArr <string>(value, false, ';'))
                });

            case "lang":
                return(new Lang
                {
                    key = value
                });

            default:
                return(null);
            }
        }