コード例 #1
0
        private static void exportFile(string excelPath, string outputDir, TableExportFormat fmt)
        {
            var data = TableExcelReader.loadFromExcel(excelPath);

            switch (fmt)
            {
            case TableExportFormat.Dat:
            {
                var exportPath = Path.Combine(outputDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(excelPath)));
                TableExcelExportDat.exportExcelFile(data, exportPath);
            }
            break;

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

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

            case TableExportFormat.Lua:
            {
                var exportPath = Path.Combine(outputDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(excelPath)));
                TableExcelExportLua.exportExcelFile(data, exportPath);
            }
            break;
            }
        }
コード例 #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.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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        private void btnSave_Clicked(object sender, RoutedEventArgs e)
        {
            try
            {
                dataGrid1.CommitEdit(DataGridEditingUnit.Row, true);

                updateDataFromDataGrid();

                var fp = filePath_.ToLower();
                if (fp.EndsWith(".xls") || fp.EndsWith(".xlsx"))
                {
                    TableExcelWriter.genExcel(data_, filePath_);
                }
                else if (fp.EndsWith(".exdat"))
                {
                    TableExcelExportDat.exportExcelFile(data_, filePath_);
                }
                else if (fp.EndsWith(".json"))
                {
                    TableExcelExportJson.exportExcelFile(data_, filePath_);
                }
                else if (fp.EndsWith(".xml"))
                {
                    TableExcelExportXml.exportExcelFile(data_, filePath_);
                }
                else if (fp.EndsWith(".lua"))
                {
                    var filePath = filePath_;
                    if (AppData.Config.FitUnity3D == true)
                    {
                        filePath += ".txt";
                    }
                    TableExcelExportLua.exportExcelFile(data_, filePath);
                }
                Window.GetWindow(this).Close();
            }
            catch (System.Exception ex)
            {
                this.ErrBox(ex.Message);
            }
        }
コード例 #5
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);
            }
        }