Esempio n. 1
0
        private void _genSingleFileImpl(string filePath, string exportDir, TableExportFormat fmt)
        {
            Log.Msg("正在分析 {0}", filePath);
            try
            {
                TableExcelData data = TableExcelReader.loadFromExcel(filePath);
                string         errmsg;
                if (!data.checkUnique(out errmsg))
                {
                    Log.Wrn(errmsg);
                }
                switch (fmt)
                {
                case TableExportFormat.Json:
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportJson.exportExcelFile(data, exportPath);
                }
                break;

                    /*
                     * case TableExportFormat.Dat:
                     * {
                     *  var exportPath = Path.Combine(exportDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(filePath)));
                     *  TableExcelExportDat.exportExcelFile(data, exportPath);
                     * }
                     * break;
                     * case TableExportFormat.Xml:
                     * {
                     *  var exportPath = Path.Combine(exportDir, string.Format("{0}.xml", Path.GetFileNameWithoutExtension(filePath)));
                     *  TableExcelExportXml.exportExcelFile(data, exportPath);
                     * }
                     * break;
                     * case TableExportFormat.Lua:
                     * {
                     *  var exportPath = Path.Combine(exportDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(filePath)));
                     *  TableExcelExportLua.exportExcelFile(data, exportPath);
                     * }
                     * break;
                     */
                }
                //生成.h文件
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.h", Path.GetFileNameWithoutExtension(filePath)));
                    var outCppData = CreateTableCpp.toFileData(Path.GetFileNameWithoutExtension(filePath), data.Headers);
                    File.WriteAllBytes(exportPath, Encoding.UTF8.GetBytes(outCppData));
                }

                Log.Msg("生成成功");
            }
            catch (System.Exception ex)
            {
                Log.Err(ex.Message);
            }
        }
Esempio n. 2
0
        private void _genSingleFileImpl(string filePath, string exportDir, TableExportFormat fmt)
        {
            Log.Msg("正在分析 {0}", filePath);
            try
            {
                TableExcelData data = TableExcelReader.loadFromExcel(filePath);
                string         errmsg;
                if (!data.checkUnique(out errmsg))
                {
                    Log.Wrn(errmsg);
                }
                switch (fmt)
                {
                case TableExportFormat.Dat:
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportDat.exportExcelFile(data, exportPath);
                }
                break;

                case TableExportFormat.Json:
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportJson.exportExcelFile(data, exportPath);
                }
                break;

                case TableExportFormat.Xml:
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.xml", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportXml.exportExcelFile(data, exportPath);
                }
                break;

                case TableExportFormat.Lua:
                {
                    var exportPath = Path.Combine(exportDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportLua.exportExcelFile(data, exportPath);
                }
                break;
                }
                Log.Msg("生成成功");
            }
            catch (System.Exception ex)
            {
                Log.Err(ex.Message);
            }
        }
Esempio n. 3
0
        private bool _genSingleFileImpl(string filePath, string exportDir, TableExportFormat fmt)
        {
            Log.Msg("----------正在导出 {0}----------", filePath);
            string exportPath = exportDir;

            try
            {
                TableExcelData data = TableExcelReader.loadFromExcel(filePath);
                string         errmsg;
                if (!data.checkUnique(out errmsg))
                {
                    throw new System.Exception(errmsg);
                }
                if (!data.checkDataType(out errmsg))
                {
                    throw new System.Exception(errmsg);
                }
                switch (fmt)
                {
                case TableExportFormat.Dat:
                {
                    exportPath = Path.Combine(exportDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportDat.exportExcelFile(data, exportPath);
                }
                break;

                case TableExportFormat.Json:
                {
                    // export json
                    exportPath = Path.Combine(exportDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportJson.exportExcelFile(data, exportPath);

                    // export cs
                    string fileName = Path.GetFileNameWithoutExtension(filePath);
                    fileName   = fileName.Substring(0, 1).ToUpper() + fileName.Substring(1);
                    exportPath = Path.Combine(exportDir, string.Format($"{ fileName }.cs"));
                    TableExcelExportCs.ExportExcelFile(data, exportPath);

                    // export csEx
                    exportPath = Path.Combine(exportDir, string.Format($"{ fileName }.Ex.cs"));
                    if (!File.Exists(exportPath))
                    {
                        TableExcelExportCsEx.ExportExcelFile(data, exportPath, fileName);
                    }
                }
                break;

                case TableExportFormat.Xml:
                {
                    exportPath = Path.Combine(exportDir, string.Format("{0}.xml", Path.GetFileNameWithoutExtension(filePath)));
                    TableExcelExportXml.exportExcelFile(data, exportPath);
                }
                break;

                case TableExportFormat.Lua:
                {
                    exportPath = Path.Combine(exportDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(filePath)));
                    if (AppData.Config.FitUnity3D == true)
                    {
                        exportPath += ".txt";
                    }
                    TableExcelExportLua.exportExcelFile(data, exportPath);
                }
                break;
                }
                Log.Msg("----------导出成功 {0} ----------", exportPath);
                return(true);
            }
            catch (System.Exception ex)
            {
                Log.Err(ex.Message);
                Log.Err("----------导出失败 {0} ----------", exportPath);
                return(false);
            }
        }