Exemple #1
0
        static void Main(string[] args)
        {
            ConfigMgr.GetInstance().LoadConfig("./config.xml");
            Workbook workbook = new Workbook("./data.xlsx");

            workbook.ReadWorkbook();

            List <DataSheetInfo> dSheet = workbook.ConvertToDataSheet();

            foreach (DataSheetInfo s in dSheet)
            {
                new DataToOptimizeLuaExporter(s, ConfigMgr.GetInstance().GetConfig().exportConfigs[0]).Export();
            }
            LogMsgMgr.GetInstance().PrintMsg();
            Console.ReadKey();
        }
        public void Export()
        {
            string dirPath = exportConfig.targetDir;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            summary.Export(dataSheet.Name, dirPath);

            text.Export(dataSheet.Name + "Text_" + ConfigMgr.GetInstance().GetConfig().languageConfig.package, dirPath);
            str.Export(dataSheet.Name + "Str", dirPath);

            string subDirPath = dirPath + "/" + dataSheet.Name;

            if (!Directory.Exists(subDirPath))
            {
                Directory.CreateDirectory(subDirPath);
                //Directory.Delete(subDirPath, true);
            }

            for (int i = 1; i <= summary.subformCount; i++)
            {
                int startIndex = (i - 1) * exportConfig.subform;
                int endIndex   = i * exportConfig.subform - 1;
                if (endIndex >= dataSheet.GetContentCount())
                {
                    endIndex = dataSheet.GetContentCount() - 1;
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("local {0}_{1} = {{\n", dataSheet.Name, i);

                for (int k = startIndex; k <= endIndex; k++)
                {
                    int dataID = int.Parse((string)dataSheet.GetContentValue(k, 0));
                    sb.AppendFormat("    [{0}] = {{\n", dataID);
                    for (int j = 0; j < dataSheet.GetFieldCount(); j++)
                    {
                        DataFieldInfo dfInfo = dataSheet.GetFieldInfo(j);
                        object        data   = dataSheet.GetContentValue(k, j, true);
                        if (dfInfo.type == DataFieldType.Stringt)
                        {
                            data = "" + text.GetIndex((string)data);
                        }
                        else if (dfInfo.type == DataFieldType.String || dfInfo.type == DataFieldType.Res)
                        {
                            data = "" + str.GetIndex((string)data);
                        }
                        if (summary.IsInDefault(dfInfo, data))
                        {
                            continue;
                        }
                        switch (dfInfo.type)
                        {
                        case DataFieldType.Dic:
                            break;

                        case DataFieldType.Array:
                            break;

                        case DataFieldType.Bool:
                        case DataFieldType.Float:
                        case DataFieldType.Int:
                        case DataFieldType.Long:
                        case DataFieldType.Double:
                        case DataFieldType.Ref:
                        {
                            string strData = (string)data;
                            sb.AppendFormat("        {0} = {1},\n", dfInfo.name, strData.ToLower());
                        }
                        break;

                        case DataFieldType.String:
                        case DataFieldType.Stringt:
                        case DataFieldType.Res:
                        {
                            string strData = (string)data;
                            sb.AppendFormat("        {0}_index = {1},\n", dfInfo.name, strData.ToLower());
                        }
                        break;
                        }
                    }
                    sb.AppendLine("    },");
                }

                sb.AppendLine("}");
                sb.AppendFormat("SetLooseReadonly({0}_{1})\n", dataSheet.Name, i);
                sb.AppendFormat("return {0}_{1}\n", dataSheet.Name, i);

                string fileContent = sb.ToString();
                File.WriteAllText(subDirPath + "/" + dataSheet.Name + "_" + i + ".lua", fileContent);
            }
        }