Example #1
0
    /// <summary>
    /// 将某张Excel表格转换为lua table内容保存到文件
    /// </summary>
    public static bool SaveErlangFile(string excelName, string tableName, string content)
    {
        try
        {
            //if (ErlangStruct.IsBeforeNameAddtb == true)
            //{
            //    if (!fileName.StartsWith("tb_"))
            //        fileName = string.Concat("tb_", fileName);
            //}
            string exportDirectoryPath = FileModule.GetExportDirectoryPath(excelName, ErlangStruct.SavePath, ErlangStruct.IsExportKeepDirectoryStructure);
            //如果文件夹不存在就创建
            if (Directory.Exists(exportDirectoryPath) == false)
            {
                Directory.CreateDirectory(exportDirectoryPath);
            }

            string       fileName2 = string.Concat(ErlangStruct.ExportNameBeforeAdd + tableName, ".", ErlangStruct.SaveExtension);
            string       savePath  = FileModule.CombinePath(exportDirectoryPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(content);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Example #2
0
    /// <summary>
    /// 将某张Excel表格转换为lua table内容保存到文件
    /// </summary>
    public static bool SaveTxtFile(Export export, string excelName, string sheetName)
    {
        try
        {
            string exportDirectoryPath = FileModule.GetExportDirectoryPath(excelName, export.ExportPath, export.IsExportKeepDirectoryStructure, false);
            //如果文件夹不存在就创建
            if (Directory.Exists(exportDirectoryPath) == false)
            {
                Directory.CreateDirectory(exportDirectoryPath);
            }

            //if (sheetName.StartsWith("'"))
            //    sheetName = sheetName.Substring(1);
            //if (sheetName.EndsWith("'"))
            //    sheetName = sheetName.Substring(0, sheetName.Length - 1);
            //if (sheetName.EndsWith("$"))
            //    sheetName = sheetName.Substring(0, sheetName.Length - 1);

            string       fileName2 = string.Concat(excelName + "-" + sheetName, ".", export.ExportExtension);
            string       savePath  = FileModule.CombinePath(exportDirectoryPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(export.ExportContent);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Example #3
0
    public bool SaveFile(string tableName, string excelName, string sheetName)
    {
        try
        {
            if (IsExportKeepDirectoryStructure == true)
            {
                ExportPath = FileModule.GetExportDirectoryPath(tableName, ExportPath, IsExportKeepDirectoryStructure, false);
            }
            //如果文件夹不存在就创建
            if (Directory.Exists(ExportPath) == false)
            {
                Directory.CreateDirectory(ExportPath);
            }

            string s = "";
            if (excelName.Contains("-"))
            {
                s = excelName.Split('-')[1];
            }

            string       fileName2 = string.Concat(excelName + "-" + sheetName, ".", ExportExtension);
            string       savePath  = FileModule.CombinePath(ExportPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(ExportContent);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch (Exception e)
        {
            AppLog.LogErrorAndExit(string.Format("导出失败:{0}", e.ToString()));
            return(false);
        }
    }
Example #4
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="ExcelName">excel名,如item-道具</param>
    /// <returns></returns>
    public bool SaveFile(string tableName)
    {
        try
        {
            if (IsExportKeepDirectoryStructure == true)
            {
                ExportPath = FileModule.GetExportDirectoryPath(tableName, ExportPath, IsExportKeepDirectoryStructure, true);
            }
            //如果文件夹不存在就创建
            if (Directory.Exists(ExportPath) == false)
            {
                Directory.CreateDirectory(ExportPath);
            }

            string       fileName2 = string.Concat(ExportNameBeforeAdd + ExportName + ExportNameAfterLanguageMark, ".", ExportExtension);
            string       savePath  = FileModule.CombinePath(ExportPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(ExportContent);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch (Exception e)
        {
            AppLog.LogErrorAndExit(string.Format("导出失败:{0}", e.ToString()));
            return(false);
        }
    }
Example #5
0
    public static bool SaveJsonFile(string excelName, string tableName, string content)
    {
        try
        {
            //string ExportJsonPath = null;
            //if (AppValues.ExportJsonPath == null)//如果不存在文件夹就创建
            //{
            //    ExportJsonPath = "ExportJson";
            //    if (!System.IO.Directory.Exists(ExportJsonPath))
            //    {
            //        System.IO.Directory.CreateDirectory(ExportJsonPath);

            //    }
            //}
            //else
            //{
            //    ExportJsonPath = AppValues.ExportJsonPath;
            //}
            string exportDirectoryPath = FileModule.GetExportDirectoryPath(excelName, JsonStruct.SavePath, JsonStruct.IsExportKeepDirectoryStructure);
            //如果文件夹不存在就创建
            if (Directory.Exists(exportDirectoryPath) == false)
            {
                Directory.CreateDirectory(exportDirectoryPath);
            }

            string       fileName2 = string.Concat(JsonStruct.ExportNameBeforeAdd + tableName, ".", JsonStruct.SaveExtension);
            string       savePath  = FileModule.CombinePath(exportDirectoryPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(content);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Example #6
0
    /// <summary>
    /// 将某张Excel表格转换为lua table内容保存到文件
    /// </summary>
    public static bool SaveHrlFile(string excelName, string tableName, string content)
    {
        try
        {
            string exportDirectoryPath = FileModule.GetExportDirectoryPath(excelName, HrlStruct.SavePath, HrlStruct.IsExportKeepDirectoryStructure);
            //如果文件夹不存在就创建
            if (Directory.Exists(exportDirectoryPath) == false)
            {
                Directory.CreateDirectory(exportDirectoryPath);
            }

            string       fileName2 = string.Concat(HrlStruct.ExportNameBeforeAdd + tableName, ".", HrlStruct.SaveExtension);
            string       savePath  = FileModule.CombinePath(exportDirectoryPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(content);
            writer.Flush();
            writer.Close();
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Example #7
0
    private static bool ExportOneMergeTable(TableInfo tableInfo, Export export, out string errorString)
    {
        try
        {
            errorString = null;

            // 存储每一行数据生成的txt文件内容
            List <StringBuilder> rowContentList = new List <StringBuilder>();

            // 生成主键列的同时,对每行的StringBuilder进行初始化,主键列只能为int、long或string型,且值不允许为空,直接转为字符串即可
            FieldInfo keyColumnFieldInfo = tableInfo.GetKeyColumnFieldInfo();
            int       rowCount           = keyColumnFieldInfo.Data.Count;
            for (int row = 0; row < rowCount; ++row)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(keyColumnFieldInfo.Data[row]);
                rowContentList.Add(stringBuilder);
            }
            // 生成其他列的内容(将array、dict这样的集合类型下属字段作为独立字段处理)
            List <FieldInfo> allFieldInfoIgnoreSetDataStructure = tableInfo.GetAllClientFieldInfoIgnoreSetDataStructure();
            for (int i = 1; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                _GetOneFieldTxtContent(allFieldInfoIgnoreSetDataStructure[i], export, rowContentList);
            }

            // 要在txt中显示 导出至数据库名字及类型
            StringBuilder tempStringBuilder = new StringBuilder();
            for (int i = 0; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                tempStringBuilder.Append(export.ExportSpaceString);
                FieldInfo fieldInfo = allFieldInfoIgnoreSetDataStructure[i];
                tempStringBuilder.Append(fieldInfo.DatabaseInfoString);
            }
            // 去掉开头多加的一个分隔符
            rowContentList.Insert(0, tempStringBuilder.Remove(0, 1));

            // 要在txt中显示 声明字段检查字符串
            StringBuilder tempStringBuilder2 = new StringBuilder();
            for (int i = 0; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                tempStringBuilder2.Append(export.ExportSpaceString);
                FieldInfo fieldInfo = allFieldInfoIgnoreSetDataStructure[i];
                tempStringBuilder2.Append(fieldInfo.CheckRule);
            }

            // 去掉开头多加的一个分隔符
            rowContentList.Insert(0, tempStringBuilder2.Remove(0, 1));

            // 要在txt中显示 Lua等客户端数据类型
            StringBuilder tempStringBuilder3 = new StringBuilder();
            for (int i = 0; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                tempStringBuilder3.Append(export.ExportSpaceString);
                FieldInfo fieldInfo = allFieldInfoIgnoreSetDataStructure[i];
                tempStringBuilder3.Append(fieldInfo.DataType);
            }

            // 去掉开头多加的一个分隔符
            rowContentList.Insert(0, tempStringBuilder3.Remove(0, 1));


            StringBuilder tempStringBuilder4 = new StringBuilder();
            for (int i = 0; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                tempStringBuilder4.Append(export.ExportSpaceString);
                FieldInfo fieldInfo = allFieldInfoIgnoreSetDataStructure[i];
                // 如果是array下属的子元素,字段名生成格式为“array字段名[从1开始的下标序号]”。dict下属的子元素,生成格式为“dict字段名.下属字段名”
                if (fieldInfo.ParentField != null)
                {
                    String    fieldName = fieldInfo.FieldName;
                    FieldInfo tempField = fieldInfo;
                    while (tempField.ParentField != null)
                    {
                        if (tempField.ParentField.DataType == DataType.Array)
                        {
                            fieldName = string.Concat(tempField.ParentField.FieldName, fieldName);
                        }
                        else if (tempField.ParentField.DataType == DataType.Dict)
                        {
                            fieldName = string.Concat(tempField.ParentField.FieldName, ".", fieldName);
                        }

                        tempField = tempField.ParentField;
                    }

                    tempStringBuilder4.Append(fieldName);
                }
                else
                {
                    tempStringBuilder4.Append(fieldInfo.FieldName);
                }
            }

            // 去掉开头多加的一个分隔符
            rowContentList.Insert(0, tempStringBuilder4.Remove(0, 1));


            // 要在txt中显示 中文字段名
            StringBuilder tempStringBuilder5 = new StringBuilder();
            for (int i = 0; i < allFieldInfoIgnoreSetDataStructure.Count; ++i)
            {
                tempStringBuilder5.Append(export.ExportSpaceString);
                FieldInfo fieldInfo = allFieldInfoIgnoreSetDataStructure[i];
                tempStringBuilder5.Append(fieldInfo.Desc.Replace("\n", "\\n"));
            }

            // 去掉开头多加的一个分隔符
            rowContentList.Insert(0, tempStringBuilder5.Remove(0, 1));

            StringBuilder content = new StringBuilder();
            foreach (StringBuilder stringBuilder in rowContentList)
            {
                content.AppendLine(stringBuilder.ToString());
            }


            if (export.ExportPath == null || export.ExportPath == "")
            {
                export.ExportPath = Path.GetDirectoryName(tableInfo.ExcelFilePath);
            }


            string s = AppValues.MergeTableList[tableInfo.TableName][0].TableName;
            string exportDirectoryPath = FileModule.GetExportDirectoryPath(s, export.ExportPath, export.IsExportKeepDirectoryStructure, false);
            //如果文件夹不存在就创建
            if (Directory.Exists(exportDirectoryPath) == false)
            {
                Directory.CreateDirectory(exportDirectoryPath);
            }

            //string xname = tableInfo.TableName;
            //if(ExcelFolder.TheLanguage !="")
            //{
            //    foreach (TableInfo tab in AppValues.MergeTableList[tableInfo.TableName])
            //    {
            //        if (ExcelMethods.GetTableName(tab.ExcelName).EndsWith(ExcelFolder.TheLanguage))
            //        {
            //            xname = tableInfo.TableName + ExcelFolder.TheLanguage;
            //        }
            //    }
            //}

            string       fileName2 = string.Concat(tableInfo.TableName + ExcelFolder.TheLanguage, ".", export.ExportExtension);
            string       savePath  = FileModule.CombinePath(exportDirectoryPath, fileName2);
            StreamWriter writer    = new StreamWriter(savePath, false, new UTF8Encoding(false));
            writer.Write(content);
            writer.Flush();
            writer.Close();

            AppLog.Log(string.Format("成功导出合并TXT:{0}", fileName2));
            errorString = null;
            return(true);
        }
        catch
        {
            errorString = string.Format("[合并]表{0}的{1}保存为txt文件失败\n", tableInfo.ExcelName, tableInfo.TableConfigData2);
            return(false);
        }
    }