From e54870fb02993cda6342e33f1793ccc88fc7c094 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 28 Oct 2021 11:25:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=B0=83=E6=95=B4=E3=80=91=E5=B0=86Ex?= =?UTF-8?q?cel2TextDiff=E6=8B=86=E6=88=90=E7=8B=AC=E7=AB=8B=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/Excel2TextDiff/Excel2TextDiff.csproj | 13 ---- src/Excel2TextDiff/Excel2TextWriter.cs | 49 ------------ src/Excel2TextDiff/Program.cs | 96 ------------------------ src/LubanTools.sln | 2 - 5 files changed, 1 insertion(+), 161 deletions(-) delete mode 100644 src/Excel2TextDiff/Excel2TextDiff.csproj delete mode 100644 src/Excel2TextDiff/Excel2TextWriter.cs delete mode 100644 src/Excel2TextDiff/Program.cs diff --git a/README.md b/README.md index aec3f6f..da082b6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ luban相较于常规的excel导表工具有以下核心优势: - 增强了excel格式。可以比较简洁地excel配置**任意复杂**的数据,像子结构、结构列表,以及更复杂的深层次的嵌套结构都能直接解析处理。 - 完备的类型系统和多原始数据支持(xml、json、lua、yaml),可以轻松表达和解析**任意复杂**的数据。意味着传统excel导表工具无法处理的技能、行为树、副本等等复杂配置,luban也能够统一处理了,彻底将程序从复杂的配置解析中解放出来。 -- 完善的工作流支持。如id的外键引用检查;资源合法性检查;灵活的数据源定义(拆表或者多表合一);灵活的分组导出机制;多种本地化支持;生成极快(日常迭代300ms以内);Excel2TextDiff工具方便diff查看excel文件的版本间差异; +- 完善的工作流支持。如id的外键引用检查;资源合法性检查;灵活的数据源定义(拆表或者多表合一);灵活的分组导出机制;多种本地化支持;生成极快(日常迭代300ms以内);[Excel2TextDiff](https://github.com/focus-creative-games/Excel2TextDiff)工具方便diff查看excel文件的版本间差异; - **LubanAssistant Excel插件**。支持把json、lua、xml等文本格式的配置数据加载到excel中,批量编辑处理,最后再保存回原文件,较好地解决大型项目中多人合作数据编辑冲突合并的问题,较好解决在编辑器中制作的配置难以在excel中批量修改的问题。 - 支持自定义代码与数据模板。强大的数据表达能力使得绝大多数项目的配置格式往往是luban的子集,因而有较低的项目迁移成本,利用模板重新适配代码和数据生成后,即使是研发已久或者上线项目也能从luban强大的数据处理能力中受益。 diff --git a/src/Excel2TextDiff/Excel2TextDiff.csproj b/src/Excel2TextDiff/Excel2TextDiff.csproj deleted file mode 100644 index 9503e57..0000000 --- a/src/Excel2TextDiff/Excel2TextDiff.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - Exe - net5.0 - - - - - - - - diff --git a/src/Excel2TextDiff/Excel2TextWriter.cs b/src/Excel2TextDiff/Excel2TextWriter.cs deleted file mode 100644 index 91eab2c..0000000 --- a/src/Excel2TextDiff/Excel2TextWriter.cs +++ /dev/null @@ -1,49 +0,0 @@ -using ExcelDataReader; -using System.Collections.Generic; -using System.IO; - -namespace Excel2TextDiff -{ - class Excel2TextWriter - { - public void TransformToTextAndSave(string excelFile, string outputTextFile) - { - var lines = new List(); - using var excelFileStream = new FileStream(excelFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - string ext = Path.GetExtension(excelFile); - using (var reader = ext != ".csv" ? ExcelReaderFactory.CreateReader(excelFileStream) : ExcelReaderFactory.CreateCsvReader(excelFileStream)) - { - do - { - lines.Add($"===[{reader.Name ?? ""}]==="); - LoadRows(reader, lines); - } while (reader.NextResult()); - } - File.WriteAllLines(outputTextFile, lines, System.Text.Encoding.UTF8); - } - - private void LoadRows(IExcelDataReader reader, List lines) - { - var row = new List(); - while (reader.Read()) - { - row.Clear(); - for (int i = 0, n = reader.FieldCount; i < n; i++) - { - object cell = reader.GetValue(i); - row.Add(cell != null ? cell.ToString() : ""); - } - // 只保留到最后一个非空白单元格 - int lastNotEmptyIndex = row.FindLastIndex(s => !string.IsNullOrEmpty(s)); - if (lastNotEmptyIndex >= 0) - { - lines.Add(string.Join(',', row.GetRange(0, lastNotEmptyIndex + 1))); - } - else - { - // 忽略空白行,没必要diff这个 - } - } - } - } -} diff --git a/src/Excel2TextDiff/Program.cs b/src/Excel2TextDiff/Program.cs deleted file mode 100644 index 9a4a31f..0000000 --- a/src/Excel2TextDiff/Program.cs +++ /dev/null @@ -1,96 +0,0 @@ -using CommandLine; -using CommandLine.Text; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; - -namespace Excel2TextDiff -{ - class CommandLineOptions - { - [Option('t', SetName = "transform", HelpText = "transform excel to text file")] - public bool IsTransform { get; set; } - - [Option('d', SetName = "diff", HelpText = "transform and diff file")] - public bool IsDiff { get; set; } - - [Option('p', SetName = "diff", Required = false, HelpText = "3rd diff program. default TortoiseMerge")] - public string DiffProgram { get; set; } - - [Option('f', SetName = "diff", Required = false, HelpText = "3rd diff program argument format. default is TortoiseMerge format:'/base:{0} /mine:{1}'")] - public string DiffProgramArgumentFormat { get; set; } - - [Value(0)] - public IList Files { get; set; } - - [Usage()] - public static IEnumerable Examples => new List - { - new Example("tranfrom to text", new CommandLineOptions { IsTransform = true, Files = new List{"a.xlsx", "a.txt" } }), - new Example("diff two excel file", new CommandLineOptions{ IsDiff = true, Files = new List{"a.xlsx", "b.xlsx"}}), - new Example("diff two excel file with TortoiseMerge", new CommandLineOptions{ IsDiff = true, DiffProgram = "TortoiseMerge",DiffProgramArgumentFormat = "/base:{0} /mine:{1}", Files = new List{"a.xlsx", "b.xlsx"}}), - }; - } - - class Program - { - static void Main(string[] args) - { - var options = ParseOptions(args); - - System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); - var writer = new Excel2TextWriter(); - - if (options.IsTransform) - { - if (options.Files.Count != 2) - { - Console.WriteLine("Usage: Excel2TextDiff -t "); - Environment.Exit(1); - } - - writer.TransformToTextAndSave(options.Files[0], options.Files[1]); - } - else - { - if (options.Files.Count != 2) - { - Console.WriteLine("Usage: Excel2TextDiff -d "); - Environment.Exit(1); - } - - var diffProgame = options.DiffProgram ?? "TortoiseMerge.exe"; - - var tempTxt1 = Path.GetTempFileName(); - writer.TransformToTextAndSave(options.Files[0], tempTxt1); - - var tempTxt2 = Path.GetTempFileName(); - writer.TransformToTextAndSave(options.Files[1], tempTxt2); - - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.FileName = diffProgame; - string argsFormation = options.DiffProgramArgumentFormat ?? "/base:{0} /mine:{1}"; - startInfo.Arguments = string.Format(argsFormation, tempTxt1, tempTxt2); - Process.Start(startInfo); - } - } - - private static CommandLineOptions ParseOptions(String[] args) - { - var helpWriter = new StringWriter(); - var parser = new Parser(ps => - { - ps.HelpWriter = helpWriter; - }); - - var result = parser.ParseArguments(args); - if (result.Tag == ParserResultType.NotParsed) - { - Console.Error.WriteLine(helpWriter.ToString()); - Environment.Exit(1); - } - return ((Parsed)result).Value; - } - } -} diff --git a/src/LubanTools.sln b/src/LubanTools.sln index ecfad67..780738d 100644 --- a/src/LubanTools.sln +++ b/src/LubanTools.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29418.71 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excel2TextDiff", "Excel2TextDiff\Excel2TextDiff.csproj", "{9477226F-469E-458F-A3AD-9115D777A65A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LubanAssistant", "LubanAssistant\LubanAssistant.csproj", "{353807D5-2074-42CD-AD69-F3F59D359E57}" EndProject Global