public void refreshUIByTableExcelData(TableExcelData data) { data_ = data; DataTable dt = new DataTable(); //columns foreach (var hdr in data.Headers) { dt.Columns.Add(new DataColumn(hdr.FieldName, typeof(string))); } //rows foreach (var row in data.Rows) { DataRow dr = dt.NewRow(); for (int i = 0; i < data.Headers.Count; i++) { var hdr = data.Headers[i]; dr[hdr.FieldName] = row.StrList[i]; } dt.Rows.Add(dr); } dataGrid1.ItemsSource = dt.DefaultView; }
private void btnSetting_Clicked(object sender, RoutedEventArgs e) { var panel = new HeaderPage(); panel.IsNewFileMode = false; panel.refreshDislpay(data_.Headers); var pw = new PopupWindow(panel); pw.ResizeMode = ResizeMode.CanResize; pw.Owner = Window.GetWindow(this); pw.Title = string.Format("设置字段 -- {0}", filePath_); pw.MinWidth = 600; pw.MinHeight = 400; if (pw.ShowDialog() == true) { var headers = panel.Headers; var tmp = new TableExcelData(headers, new List <TableExcelRow>()); var arr = headers.Select(a => data_.Headers.FindIndex(b => b.FieldName == a.FieldName)).ToArray(); foreach (var row in data_.Rows) { var trow = new TableExcelRow(); trow.StrList = arr.Select(idx => idx < 0 ? string.Empty : row.StrList[idx]).ToList(); tmp.Rows.Add(trow); } refreshUIByTableExcelData(tmp); } }
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); } }
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); } }
public void openExcelView(TableExcelData data, string filePath) { var panel = new FrameExcelView(); panel.refreshUIByTableExcelData(data); panel.setFilePath(filePath); var pw = new PopupWindow(panel); pw.ResizeMode = ResizeMode.CanResize; pw.Owner = Window.GetWindow(this); pw.Title = string.Format("查看配置表 -- {0}", filePath); pw.MinWidth = 600; pw.MinHeight = 400; if (pw.ShowDialog() == true) { } }
public void editForExcel(string filePath) { if (!File.Exists(filePath)) { Log.Err("源文件不存在! {0}", filePath); return; } try { TableExcelData data = TableExcelReader.loadFromExcel(filePath); openExcelView(data, filePath); } catch (System.Exception ex) { Log.Err(ex.Message); } }
private static void openEditUI(TableExcelData data, string fullPath) { var panel = new FrameExcelView(); panel.refreshUIByTableExcelData(data); panel.setFilePath(fullPath); var pw = new PopupWindow(panel); pw.ResizeMode = ResizeMode.CanResize; pw.Title = string.Format("查看配置表 -- {0}", fullPath); pw.MinWidth = 600; pw.MinHeight = 400; pw.ShowInTaskbar = true; pw.WindowStartupLocation = WindowStartupLocation.CenterScreen; App app = new App(); app.InitializeComponent(); app.Run((Window)pw); }
public void rectifyFileFormat(string filePath) { if (!File.Exists(filePath)) { Log.Err("源文件不存在! {0}", filePath); return; } Log.Msg("================================================="); try { Log.Msg("正在优化 {0}", filePath); TableExcelData data = TableExcelReader.loadFromExcel(filePath); TableExcelWriter.genExcel(data, filePath); Log.Msg("优化完毕!"); } catch (System.Exception ex) { Log.Err(ex.Message); } }
public void rectifyAllFileFormat(List <string> files) { if (files.Count == 0) { Log.Wrn("没有要优化的文件"); return; } Log.Msg("================================================="); foreach (var filePath in files) { try { Log.Msg("正在优化 {0}", filePath); TableExcelData data = TableExcelReader.loadFromExcel(filePath); TableExcelWriter.genExcel(data, filePath); } catch (System.Exception ex) { Log.Err(ex.Message); } } Log.Msg("优化完毕!"); }
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); } }