├── .gitattributes ├── .gitignore ├── README.md ├── bin.zip ├── bin ├── ICSharpCode.SharpZipLib.dll ├── NPOI.OOXML.dll ├── NPOI.OpenXml4Net.dll ├── NPOI.OpenXmlFormats.dll ├── NPOI.dll ├── Newtonsoft.Json.dll └── tablegen2.exe ├── doc ├── image1.png ├── image2.png └── image3.png ├── tablegen2.sln └── tablegen2 ├── App.config ├── App.xaml ├── App.xaml.cs ├── ApplicationEvents.cs ├── BoolToVisibilityConverter.cs ├── CommandHelper.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── StaticResources.xaml ├── app.ico ├── common ├── AppData.cs ├── BinaryExtension.cs ├── FrameworkExtension.cs ├── GzipHelper.cs ├── JsonConfig.cs ├── Log.cs ├── MessageBoxExtensions.cs └── Util.cs ├── layouts ├── common │ ├── ButtonDark.xaml │ ├── ButtonDark.xaml.cs │ ├── ButtonLight.xaml │ ├── ButtonLight.xaml.cs │ ├── HelperPanel.xaml │ ├── HelperPanel.xaml.cs │ ├── ListItemBase.cs │ ├── PopupWindow.xaml │ ├── PopupWindow.xaml.cs │ ├── WaitingControl.xaml │ └── WaitingControl.xaml.cs ├── framework │ ├── FrameConsole.xaml │ ├── FrameConsole.xaml.cs │ ├── FrameExcelView.xaml │ ├── FrameExcelView.xaml.cs │ ├── FrameFileTree.xaml │ ├── FrameFileTree.xaml.cs │ ├── FrameSetting.xaml │ ├── FrameSetting.xaml.cs │ ├── FrameSettingMore.xaml │ ├── FrameSettingMore.xaml.cs │ ├── FrameToolBar.xaml │ ├── FrameToolBar.xaml.cs │ ├── TreeListItem.xaml │ ├── TreeListItem.xaml.cs │ ├── TreeListView.xaml │ └── TreeListView.xaml.cs └── header │ ├── HeaderFieldEdit.xaml │ ├── HeaderFieldEdit.xaml.cs │ ├── HeaderListItem.xaml │ ├── HeaderListItem.xaml.cs │ ├── HeaderListView.xaml │ ├── HeaderListView.xaml.cs │ ├── HeaderPage.xaml │ └── HeaderPage.xaml.cs ├── logic └── parser │ ├── TableExcelData.cs │ ├── TableExcelExportDat.cs │ ├── TableExcelExportJson.cs │ ├── TableExcelExportLua.cs │ ├── TableExcelExportXml.cs │ ├── TableExcelHeader.cs │ ├── TableExcelImportDat.cs │ ├── TableExcelReader.cs │ ├── TableExcelRow.cs │ ├── TableExcelWriter.cs │ ├── TableExportFormat.cs │ └── TableGenConfig.cs ├── packages ├── ICSharpCode.SharpZipLib.dll ├── NPOI.OOXML.dll ├── NPOI.OpenXml4Net.dll ├── NPOI.OpenXmlFormats.dll ├── NPOI.XML ├── NPOI.dll ├── Newtonsoft.Json.dll └── Newtonsoft.Json.xml ├── res └── excel.png └── tablegen2.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 导表工具 2 | ====================== 3 | 4 | 项目主页:https://github.com/monkey256/ExcelExport 5 | 6 | ![Image text](https://raw.githubusercontent.com/monkey256/ExcelExport/master/doc/image1.png) 7 | ![Image text](https://raw.githubusercontent.com/monkey256/ExcelExport/master/doc/image2.png) 8 | ![Image text](https://raw.githubusercontent.com/monkey256/ExcelExport/master/doc/image3.png) 9 | -------------------------------------------------------------------------------- /bin.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin.zip -------------------------------------------------------------------------------- /bin/ICSharpCode.SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/ICSharpCode.SharpZipLib.dll -------------------------------------------------------------------------------- /bin/NPOI.OOXML.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/NPOI.OOXML.dll -------------------------------------------------------------------------------- /bin/NPOI.OpenXml4Net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/NPOI.OpenXml4Net.dll -------------------------------------------------------------------------------- /bin/NPOI.OpenXmlFormats.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/NPOI.OpenXmlFormats.dll -------------------------------------------------------------------------------- /bin/NPOI.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/NPOI.dll -------------------------------------------------------------------------------- /bin/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /bin/tablegen2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/bin/tablegen2.exe -------------------------------------------------------------------------------- /doc/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/doc/image1.png -------------------------------------------------------------------------------- /doc/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/doc/image2.png -------------------------------------------------------------------------------- /doc/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/doc/image3.png -------------------------------------------------------------------------------- /tablegen2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tablegen2", "tablegen2\tablegen2.csproj", "{4D5AEC09-00D5-41EA-9BE3-67D090C7FCC1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4D5AEC09-00D5-41EA-9BE3-67D090C7FCC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4D5AEC09-00D5-41EA-9BE3-67D090C7FCC1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4D5AEC09-00D5-41EA-9BE3-67D090C7FCC1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4D5AEC09-00D5-41EA-9BE3-67D090C7FCC1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /tablegen2/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tablegen2/App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tablegen2/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace tablegen2 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tablegen2/ApplicationEvents.cs: -------------------------------------------------------------------------------- 1 | namespace tablegen2 2 | { 3 | static class ApplicationEvents 4 | { 5 | public static void Application_Startup() 6 | { 7 | AppData.loadConfig(); 8 | } 9 | 10 | public static void Application_Exit() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tablegen2/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace tablegen2 7 | { 8 | class BoolToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | return (bool)value ? Visibility.Visible : Visibility.Hidden; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 16 | { 17 | throw new NotSupportedException(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tablegen2/CommandHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Windows; 5 | using tablegen2.logic; 6 | using tablegen2.layouts; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | 10 | namespace tablegen2 11 | { 12 | internal enum CommandType 13 | { 14 | Unknown = 0, 15 | Help, 16 | OpenDatFile, 17 | OpenExcelFile, 18 | ExportFiles, 19 | } 20 | 21 | internal static class CommandHelper 22 | { 23 | //-h|-help|/h|/help 24 | //fullPath.exdat 25 | //fullPath.xls|.xlsx 26 | //-i excelFullPath|excelDir -o outputDir -t xml|json|lua|dat 27 | 28 | public static CommandType Command { get; internal set; } 29 | 30 | public static string OpenDatFullPath { get; internal set; } 31 | 32 | public static string OpenExcelFullPath { get; internal set; } 33 | 34 | public static string ExportInputPath { get; internal set; } 35 | public static string ExportOutputDir { get; internal set; } 36 | public static string ExportType { get; internal set; } 37 | 38 | static CommandHelper() 39 | { 40 | _analyzeCommandParameter(); 41 | } 42 | 43 | public static void MsgBox(string str, params object[] args) 44 | { 45 | System.Windows.MessageBox.Show( 46 | string.Format(str, args), 47 | "提示", 48 | System.Windows.MessageBoxButton.OK, 49 | System.Windows.MessageBoxImage.Information); 50 | } 51 | 52 | private static void _analyzeCommandParameter() 53 | { 54 | Command = CommandType.Unknown; 55 | 56 | do 57 | { 58 | string[] arr = Environment.GetCommandLineArgs(); 59 | if (arr.Length == 0) 60 | break; 61 | 62 | string[] cpy = arr; 63 | string s = arr[0]; 64 | if (s.Contains("vshost") || s.ToLower() == Util.ModulePath.ToLower()) 65 | { 66 | cpy = new string[arr.Length - 1]; 67 | Array.Copy(arr, 1, cpy, 0, arr.Length - 1); 68 | } 69 | 70 | #region help 71 | if (cpy.Length == 1) 72 | { 73 | var c = cpy[0]; 74 | if (c == "-h" || c == "-help" || c == "/h" || c == "/help") 75 | { 76 | Command = CommandType.Help; 77 | break; 78 | } 79 | } 80 | #endregion 81 | 82 | #region open dat 83 | if (cpy.Length == 1 && File.Exists(cpy[0])) 84 | { 85 | if (Path.GetExtension(cpy[0]).ToLower() == ".exdat") 86 | { 87 | Command = CommandType.OpenDatFile; 88 | OpenDatFullPath = cpy[0]; 89 | break; 90 | } 91 | } 92 | #endregion 93 | 94 | #region open excel 95 | if (cpy.Length == 1 && File.Exists(cpy[0])) 96 | { 97 | var ext = Path.GetExtension(cpy[0]).ToLower(); 98 | if (ext == ".xls" || ext == ".xlsx") 99 | { 100 | Command = CommandType.OpenExcelFile; 101 | OpenExcelFullPath = cpy[0]; 102 | break; 103 | } 104 | } 105 | #endregion 106 | 107 | #region convert excel 108 | if (cpy.Length == 6) 109 | { 110 | var ps = new Dictionary(); 111 | ps[cpy[0]] = cpy[1]; 112 | ps[cpy[2]] = cpy[3]; 113 | ps[cpy[4]] = cpy[5]; 114 | var ks = ps.Keys.ToList(); 115 | ks.Sort(); 116 | if (string.Concat(ks) == "-i-o-t") 117 | { 118 | Command = CommandType.ExportFiles; 119 | ExportInputPath = ps["-i"]; 120 | ExportOutputDir = ps["-o"]; 121 | ExportType = ps["-t"]; 122 | break; 123 | } 124 | } 125 | #endregion 126 | } while (false); 127 | } 128 | 129 | public static void processHelp() 130 | { 131 | var sb = new StringBuilder(); 132 | sb.AppendLine("使用说明"); 133 | sb.AppendLine("1.datPath"); 134 | sb.AppendLine(" 功能说明:打开并查看.exdat文件"); 135 | sb.AppendLine("2.excelPath"); 136 | sb.AppendLine(" 功能说明:打开并查看.xls或.xlsx文件"); 137 | sb.AppendLine("3.-i excelFullPath|excelDir -o outputDir -t xml|json|lua|dat"); 138 | sb.AppendLine(" 功能说明:将Excel表或整个目录导出指定格式的数据文件"); 139 | MsgBox(sb.ToString()); 140 | } 141 | 142 | public static void processOpenDatFile() 143 | { 144 | try 145 | { 146 | var data = TableExcelImportDat.importFile(OpenDatFullPath); 147 | openEditUI(data, OpenDatFullPath); 148 | } 149 | catch (System.Exception ex) 150 | { 151 | MsgBox(ex.Message); 152 | } 153 | } 154 | 155 | public static void processOpenExcelFile() 156 | { 157 | try 158 | { 159 | var data = TableExcelReader.loadFromExcel(OpenExcelFullPath); 160 | openEditUI(data, OpenExcelFullPath); 161 | } 162 | catch (System.Exception ex) 163 | { 164 | MsgBox(ex.Message); 165 | } 166 | } 167 | 168 | private static void openEditUI(TableExcelData data, string fullPath) 169 | { 170 | var panel = new FrameExcelView(); 171 | panel.refreshUIByTableExcelData(data); 172 | panel.setFilePath(fullPath); 173 | 174 | var pw = new PopupWindow(panel); 175 | pw.ResizeMode = ResizeMode.CanResize; 176 | pw.Title = string.Format("查看配置表 -- {0}", fullPath); 177 | pw.MinWidth = 600; 178 | pw.MinHeight = 400; 179 | pw.ShowInTaskbar = true; 180 | pw.WindowStartupLocation = WindowStartupLocation.CenterScreen; 181 | 182 | App app = new App(); 183 | app.InitializeComponent(); 184 | app.Run((Window)pw); 185 | } 186 | 187 | public static void processExportFiles() 188 | { 189 | var lst = new List(); 190 | if (Directory.Exists(ExportInputPath)) 191 | { 192 | lst = Directory.GetFiles(ExportInputPath, "*.xls", SearchOption.AllDirectories).ToList(); 193 | lst.Union(Directory.GetFiles(ExportInputPath, "*.xlsx", SearchOption.AllDirectories)); 194 | } 195 | else if (File.Exists(ExportInputPath)) 196 | { 197 | lst.Add(ExportInputPath); 198 | } 199 | else 200 | { 201 | MsgBox("文件或目录不存在! {0}", ExportInputPath); 202 | return; 203 | } 204 | 205 | Util.MakesureFolderExist(ExportOutputDir); 206 | if (!Directory.Exists(ExportOutputDir)) 207 | { 208 | MsgBox("无法创建目录! {0}", ExportOutputDir); 209 | return; 210 | } 211 | 212 | var fmt = TableExportFormat.Unknown; 213 | switch (ExportType.ToLower()) 214 | { 215 | case "xml": 216 | fmt = TableExportFormat.Xml; 217 | break; 218 | case "json": 219 | fmt = TableExportFormat.Json; 220 | break; 221 | case "lua": 222 | fmt = TableExportFormat.Lua; 223 | break; 224 | case "dat": 225 | fmt = TableExportFormat.Dat; 226 | break; 227 | } 228 | if (fmt == TableExportFormat.Unknown) 229 | { 230 | MsgBox("无法识别的导出格式! {0}", ExportType); 231 | return; 232 | } 233 | 234 | foreach (var filePath in lst) 235 | { 236 | try 237 | { 238 | exportFile(filePath, ExportOutputDir, fmt); 239 | } 240 | catch (System.Exception ex) 241 | { 242 | MsgBox("转换文件'{0}'时出错:\n{1}", filePath, ex.Message); 243 | return; 244 | } 245 | } 246 | } 247 | 248 | private static void exportFile(string excelPath, string outputDir, TableExportFormat fmt) 249 | { 250 | var data = TableExcelReader.loadFromExcel(excelPath); 251 | switch (fmt) 252 | { 253 | case TableExportFormat.Dat: 254 | { 255 | var exportPath = Path.Combine(outputDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(excelPath))); 256 | TableExcelExportDat.exportExcelFile(data, exportPath); 257 | } 258 | break; 259 | case TableExportFormat.Json: 260 | { 261 | var exportPath = Path.Combine(outputDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(excelPath))); 262 | TableExcelExportJson.exportExcelFile(data, exportPath); 263 | } 264 | break; 265 | case TableExportFormat.Xml: 266 | { 267 | var exportPath = Path.Combine(outputDir, string.Format("{0}.xml", Path.GetFileNameWithoutExtension(excelPath))); 268 | TableExcelExportXml.exportExcelFile(data, exportPath); 269 | } 270 | break; 271 | case TableExportFormat.Lua: 272 | { 273 | var exportPath = Path.Combine(outputDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(excelPath))); 274 | TableExcelExportLua.exportExcelFile(data, exportPath); 275 | } 276 | break; 277 | } 278 | } 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /tablegen2/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tablegen2/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Windows; 5 | using System.Windows.Input; 6 | using System.Windows.Media; 7 | using tablegen2.layouts; 8 | using tablegen2.logic; 9 | 10 | namespace tablegen2 11 | { 12 | /// 13 | /// MainWindow.xaml 的交互逻辑 14 | /// 15 | public partial class MainWindow : Window 16 | { 17 | public MainWindow() 18 | { 19 | AppData.MainWindow = this; 20 | 21 | InitializeComponent(); 22 | 23 | setting.ExcelDirChanged += () => tree.refreshExcelPath(AppData.Config.ExcelDir); 24 | setting.ExportFormatChanged += () => refreshButtonGenAll(); 25 | setting.MoreSettingEvent += () => _flipMoreSettingPanel(); 26 | tree.OpenExcelRequest += () => setting.browseExcelDirectory(); 27 | 28 | if (AppData.Config != null) 29 | refreshButtonGenAll(); 30 | } 31 | 32 | #region 事件处理 33 | private void Window_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e) 34 | { 35 | if (e.Key == Key.F1) 36 | { 37 | _flipHelpPanel(); 38 | e.Handled = true; 39 | } 40 | } 41 | 42 | private void btnHelp_Clicked(object sender, RoutedEventArgs e) 43 | { 44 | _flipHelpPanel(); 45 | } 46 | 47 | private void btnGenAll_Clicked(object sender, RoutedEventArgs e) 48 | { 49 | string excelDir = AppData.Config.ExcelDir; 50 | string exportDir = AppData.Config.ExportDir; 51 | TableExportFormat fmt = AppData.Config.ExportFormat; 52 | 53 | if (string.IsNullOrEmpty(excelDir) || !Directory.Exists(excelDir)) 54 | { 55 | Log.Err("请选择合法的Excel配置目录!"); 56 | return; 57 | } 58 | 59 | if (string.IsNullOrEmpty(exportDir) || !Directory.Exists(exportDir)) 60 | { 61 | Log.Err("请选择合法的导出目录!"); 62 | return; 63 | } 64 | 65 | if (fmt == TableExportFormat.Unknown) 66 | { 67 | Log.Err("请选择导出数据格式!"); 68 | return; 69 | } 70 | 71 | var excels = tree.AllExcels.ToList(); 72 | if (excels.Count == 0) 73 | { 74 | Log.Wrn("您选择的配置目录中不包含任何Excel文件! 目录:{0}", excelDir); 75 | return; 76 | } 77 | 78 | Log.Msg("================================================="); 79 | foreach (var filePath in excels) 80 | { 81 | _genSingleFileImpl(filePath, exportDir, fmt); 82 | } 83 | } 84 | #endregion 85 | 86 | public void addMessage(string msg, Color color) 87 | { 88 | if (console != null) 89 | console.addMessage(msg, color); 90 | } 91 | 92 | public void refreshButtonGenAll() 93 | { 94 | switch (AppData.Config.ExportFormat) 95 | { 96 | case TableExportFormat.Unknown: 97 | btnGenAll.IsEnabled = false; 98 | btnGenAll.Content = "请选择生成的数据格式"; 99 | break; 100 | default: 101 | btnGenAll.IsEnabled = true; 102 | btnGenAll.Content = string.Format(btnGenAll.Tag as string, AppData.Config.ExportFormat.ToString()); 103 | break; 104 | } 105 | } 106 | 107 | public void editForExcel(string filePath) 108 | { 109 | if (!File.Exists(filePath)) 110 | { 111 | Log.Err("源文件不存在! {0}", filePath); 112 | return; 113 | } 114 | 115 | try 116 | { 117 | TableExcelData data = TableExcelReader.loadFromExcel(filePath); 118 | openExcelView(data, filePath); 119 | } 120 | catch (System.Exception ex) 121 | { 122 | Log.Err(ex.Message); 123 | } 124 | } 125 | 126 | public void openExcelView(TableExcelData data, string filePath) 127 | { 128 | var panel = new FrameExcelView(); 129 | panel.refreshUIByTableExcelData(data); 130 | panel.setFilePath(filePath); 131 | 132 | var pw = new PopupWindow(panel); 133 | pw.ResizeMode = ResizeMode.CanResize; 134 | pw.Owner = Window.GetWindow(this); 135 | pw.Title = string.Format("查看配置表 -- {0}", filePath); 136 | pw.MinWidth = 600; 137 | pw.MinHeight = 400; 138 | if (pw.ShowDialog() == true) 139 | { 140 | } 141 | } 142 | 143 | public void rectifyFileFormat(string filePath) 144 | { 145 | if (!File.Exists(filePath)) 146 | { 147 | Log.Err("源文件不存在! {0}", filePath); 148 | return; 149 | } 150 | 151 | Log.Msg("================================================="); 152 | 153 | try 154 | { 155 | Log.Msg("正在优化 {0}", filePath); 156 | TableExcelData data = TableExcelReader.loadFromExcel(filePath); 157 | TableExcelWriter.genExcel(data, filePath); 158 | Log.Msg("优化完毕!"); 159 | } 160 | catch (System.Exception ex) 161 | { 162 | Log.Err(ex.Message); 163 | } 164 | } 165 | 166 | public void rectifyAllFileFormat(List files) 167 | { 168 | if (files.Count == 0) 169 | { 170 | Log.Wrn("没有要优化的文件"); 171 | return; 172 | } 173 | 174 | Log.Msg("================================================="); 175 | foreach (var filePath in files) 176 | { 177 | try 178 | { 179 | Log.Msg("正在优化 {0}", filePath); 180 | TableExcelData data = TableExcelReader.loadFromExcel(filePath); 181 | TableExcelWriter.genExcel(data, filePath); 182 | } 183 | catch (System.Exception ex) 184 | { 185 | Log.Err(ex.Message); 186 | } 187 | } 188 | Log.Msg("优化完毕!"); 189 | } 190 | 191 | public void genSingleFile(string filePath, string exportDir, TableExportFormat fmt) 192 | { 193 | if (!File.Exists(filePath)) 194 | { 195 | Log.Err("源文件不存在! {0}", filePath); 196 | return; 197 | } 198 | 199 | if (!Directory.Exists(exportDir)) 200 | { 201 | Log.Err("导出目录不存在! {0}", exportDir); 202 | return; 203 | } 204 | 205 | if (fmt == TableExportFormat.Unknown) 206 | { 207 | Log.Err("导出数据格式不合法!"); 208 | return; 209 | } 210 | 211 | Log.Msg("================================================="); 212 | _genSingleFileImpl(filePath, exportDir, fmt); 213 | } 214 | 215 | private void _genSingleFileImpl(string filePath, string exportDir, TableExportFormat fmt) 216 | { 217 | Log.Msg("正在分析 {0}", filePath); 218 | try 219 | { 220 | TableExcelData data = TableExcelReader.loadFromExcel(filePath); 221 | string errmsg; 222 | if (!data.checkUnique(out errmsg)) 223 | Log.Wrn(errmsg); 224 | switch (fmt) 225 | { 226 | case TableExportFormat.Dat: 227 | { 228 | var exportPath = Path.Combine(exportDir, string.Format("{0}.exdat", Path.GetFileNameWithoutExtension(filePath))); 229 | TableExcelExportDat.exportExcelFile(data, exportPath); 230 | } 231 | break; 232 | case TableExportFormat.Json: 233 | { 234 | var exportPath = Path.Combine(exportDir, string.Format("{0}.json", Path.GetFileNameWithoutExtension(filePath))); 235 | TableExcelExportJson.exportExcelFile(data, exportPath); 236 | } 237 | break; 238 | case TableExportFormat.Xml: 239 | { 240 | var exportPath = Path.Combine(exportDir, string.Format("{0}.xml", Path.GetFileNameWithoutExtension(filePath))); 241 | TableExcelExportXml.exportExcelFile(data, exportPath); 242 | } 243 | break; 244 | case TableExportFormat.Lua: 245 | { 246 | var exportPath = Path.Combine(exportDir, string.Format("{0}.lua", Path.GetFileNameWithoutExtension(filePath))); 247 | TableExcelExportLua.exportExcelFile(data, exportPath); 248 | } 249 | break; 250 | } 251 | Log.Msg("生成成功"); 252 | } 253 | catch (System.Exception ex) 254 | { 255 | Log.Err(ex.Message); 256 | } 257 | } 258 | 259 | private void _flipHelpPanel() 260 | { 261 | var hp = new HelperPanel(); 262 | var pw = new PopupWindow(hp); 263 | pw.Owner = Window.GetWindow(this); 264 | pw.Title = "使用说明"; 265 | pw.ShowDialog(); 266 | } 267 | 268 | private void _flipMoreSettingPanel() 269 | { 270 | var fsm = new FrameSettingMore(); 271 | var pw = new PopupWindow(fsm); 272 | pw.Owner = Window.GetWindow(this); 273 | pw.Title = "更多设置"; 274 | pw.ShowDialog(); 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /tablegen2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace tablegen2 5 | { 6 | static class Program 7 | { 8 | /// 9 | /// 应用程序的主入口点。 10 | /// 11 | [STAThread] 12 | static void Main(string[] args) 13 | { 14 | ApplicationEvents.Application_Startup(); 15 | if (CommandHelper.Command == CommandType.Help) 16 | { 17 | CommandHelper.processHelp(); 18 | } 19 | else if (CommandHelper.Command == CommandType.OpenDatFile) 20 | { 21 | CommandHelper.processOpenDatFile(); 22 | } 23 | else if (CommandHelper.Command == CommandType.OpenExcelFile) 24 | { 25 | CommandHelper.processOpenExcelFile(); 26 | } 27 | else if (CommandHelper.Command == CommandType.ExportFiles) 28 | { 29 | CommandHelper.processExportFiles(); 30 | } 31 | else 32 | { 33 | App app = new App(); 34 | app.InitializeComponent(); 35 | app.Run((Window)new MainWindow()); 36 | } 37 | ApplicationEvents.Application_Exit(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tablegen2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("tablegen2")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("tablegen2")] 15 | [assembly: AssemblyCopyright("Copyright © 2018")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | //将 ComVisible 设置为 false 将使此程序集中的类型 20 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请 25 | // 中的 .csproj 文件中 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(当资源未在页面 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(当资源未在页面 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 52 | // 方法是按如下所示使用“*”: : 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /tablegen2/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace tablegen2.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("tablegen2.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tablegen2/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /tablegen2/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace tablegen2.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tablegen2/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tablegen2/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/monkey256/ExcelExport/4462043b3d0d35143072dafa340a9afa8ecbaada/tablegen2/app.ico -------------------------------------------------------------------------------- /tablegen2/common/AppData.cs: -------------------------------------------------------------------------------- 1 | using tablegen2.logic; 2 | 3 | namespace tablegen2 4 | { 5 | public static class AppData 6 | { 7 | public static MainWindow MainWindow = null; 8 | public static TableGenConfig Config = null; 9 | 10 | static AppData() 11 | { 12 | } 13 | 14 | public static void loadConfig() 15 | { 16 | Config = JsonConfig.readFromFile("config.json") ?? new TableGenConfig(); 17 | //修正值 18 | if (string.IsNullOrEmpty(Config.SheetNameForField)) 19 | Config.SheetNameForField = "def"; 20 | if (string.IsNullOrEmpty(Config.SheetNameForData)) 21 | Config.SheetNameForData = "data"; 22 | } 23 | public static void saveConfig() 24 | { 25 | JsonConfig.writeToFile("config.json", Config); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tablegen2/common/BinaryExtension.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | 4 | namespace tablegen2 5 | { 6 | public static class BinaryExtension 7 | { 8 | public static void WriteUtf8String(this BinaryWriter bw, string str) 9 | { 10 | bw.Write(Encoding.UTF8.GetBytes(str)); 11 | bw.Write((byte)0); 12 | } 13 | 14 | public static string ReadUtf8String(this BinaryReader br) 15 | { 16 | MemoryStream ms = new MemoryStream(); 17 | while (true) 18 | { 19 | byte a = br.ReadByte(); 20 | if (a == 0) 21 | break; 22 | ms.WriteByte(a); 23 | } 24 | return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tablegen2/common/FrameworkExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Controls; 3 | using System.Windows; 4 | using System.Windows.Media; 5 | using System.Linq; 6 | 7 | namespace tablegen2 8 | { 9 | internal static class FrameworkExtension 10 | { 11 | public static Vector GetOffsetFromRelativeParent(this FrameworkElement e, FrameworkElement p) 12 | { 13 | p.UpdateLayout(); 14 | 15 | var r = new Vector(0, 0); 16 | var t = e; 17 | while (t != p) 18 | { 19 | if (t == null) 20 | throw new Exception("GetOffsetFromRelativeParent 异常!"); 21 | 22 | var v = VisualTreeHelper.GetOffset(t); 23 | r += v; 24 | t = VisualTreeHelper.GetParent(t) as FrameworkElement; 25 | } 26 | 27 | return r; 28 | } 29 | 30 | public static void MakesureChildVisible(this ScrollViewer sv, FrameworkElement child) 31 | { 32 | if (child == null) 33 | return; 34 | 35 | var reserve = 20; 36 | 37 | var p = child.GetOffsetFromRelativeParent(sv); 38 | p.X += sv.HorizontalOffset; 39 | p.Y += sv.VerticalOffset; 40 | 41 | if (sv.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled) 42 | { 43 | var x1 = p.X - reserve; 44 | var x2 = p.X + child.ActualWidth + reserve; 45 | var offsetx = sv.HorizontalOffset; 46 | var width = sv.ActualWidth; 47 | if (x1 < offsetx) 48 | offsetx = x1; 49 | else if (offsetx + width < x2) 50 | offsetx = x2 - width; 51 | sv.ScrollToHorizontalOffset(offsetx); 52 | } 53 | 54 | if (sv.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled) 55 | { 56 | var y1 = p.Y - reserve; 57 | var y2 = p.Y + child.ActualHeight + reserve; 58 | var offsety = sv.VerticalOffset; 59 | var height = sv.ActualHeight; 60 | if (y1 < offsety) 61 | offsety = y1; 62 | else if (offsety + height < y2) 63 | offsety = y2 - height; 64 | sv.ScrollToVerticalOffset(offsety); 65 | } 66 | } 67 | 68 | public static void SelectComboBoxItemByTag(this ComboBox cb, string tagString) 69 | { 70 | cb.SelectedItem = cb.Items.Cast().FirstOrDefault(a => (a.Tag as string) == tagString); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tablegen2/common/GzipHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.IO.Compression; 4 | 5 | namespace tablegen2 6 | { 7 | internal static class GzipHelper 8 | { 9 | public static byte[] processGZipEncode(byte[] content) 10 | { 11 | return processGZipEncode(content, content.Length); 12 | } 13 | 14 | public static byte[] processGZipEncode(byte[] content, int length) 15 | { 16 | var ms = new MemoryStream(); 17 | ms.Seek(0, SeekOrigin.Begin); 18 | var zip = new GZipStream(ms, CompressionMode.Compress, true); 19 | zip.Write(content, 0, length); 20 | zip.Close(); 21 | 22 | var r = new byte[ms.Length]; 23 | Array.Copy(ms.GetBuffer(), r, ms.Length); 24 | 25 | ms.Close(); 26 | 27 | return r; 28 | } 29 | 30 | public static byte[] processGZipDecode(byte[] content) 31 | { 32 | return processGZipDecode(content, content.Length); 33 | } 34 | 35 | public static byte[] processGZipDecode(byte[] content, int length) 36 | { 37 | var wms = new MemoryStream(); 38 | 39 | var ms = new MemoryStream(content, 0, length); 40 | ms.Seek(0, SeekOrigin.Begin); 41 | var zip = new GZipStream(ms, CompressionMode.Decompress, true); 42 | 43 | var buf = new byte[4096]; 44 | int n; 45 | while ((n = zip.Read(buf, 0, buf.Length)) != 0) 46 | { 47 | wms.Write(buf, 0, n); 48 | } 49 | 50 | zip.Close(); 51 | ms.Close(); 52 | 53 | var r = new byte[wms.Length]; 54 | Array.Copy(wms.GetBuffer(), r, wms.Length); 55 | return r; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tablegen2/common/JsonConfig.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | using System.Web.Script.Serialization; 4 | 5 | namespace tablegen2 6 | { 7 | internal static class JsonConfig 8 | { 9 | public static void writeToFile(string fileName, object target) 10 | { 11 | var jss = new JavaScriptSerializer(); 12 | var content = jss.Serialize(target); 13 | var filePath = Path.Combine(Util.WorkPath, fileName); 14 | File.WriteAllBytes(filePath, Encoding.UTF8.GetBytes(content)); 15 | } 16 | 17 | public static T readFromFile(string fileName) 18 | { 19 | try 20 | { 21 | var filePath = Path.Combine(Util.WorkPath, fileName); 22 | var fileContent = File.ReadAllBytes(filePath); 23 | var content = Encoding.UTF8.GetString(fileContent); 24 | var jss = new JavaScriptSerializer(); 25 | return jss.Deserialize(content); 26 | } 27 | catch (System.Exception) 28 | { 29 | } 30 | 31 | return default(T); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tablegen2/common/Log.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Media; 7 | 8 | namespace tablegen2 9 | { 10 | internal static class Log 11 | { 12 | public static void Msg(string msg, params object[] args) 13 | { 14 | var mw = App.Current.MainWindow as MainWindow; 15 | if (mw != null) 16 | mw.addMessage(string.Format(msg, args), Color.FromArgb(0xFF, 0, 200, 0)); 17 | } 18 | 19 | public static void Wrn(string msg, params object[] args) 20 | { 21 | var mw = App.Current.MainWindow as MainWindow; 22 | if (mw != null) 23 | mw.addMessage(string.Format(msg, args), Colors.Yellow); 24 | } 25 | 26 | public static void Err(string msg, params object[] args) 27 | { 28 | var mw = App.Current.MainWindow as MainWindow; 29 | if (mw != null) 30 | mw.addMessage(string.Format(msg, args), Color.FromArgb(0xFF, 255, 50, 50)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tablegen2/common/MessageBoxExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace tablegen2 4 | { 5 | public static class MessageBoxExtensions 6 | { 7 | public static void InfBox(this FrameworkElement owner, string str, params object[] args) 8 | { 9 | MessageBox.Show( 10 | Window.GetWindow(owner), 11 | string.Format(str, args), 12 | "提示", 13 | MessageBoxButton.OK, 14 | MessageBoxImage.Information); 15 | } 16 | 17 | public static void WrnBox(this FrameworkElement owner, string str, params object[] args) 18 | { 19 | MessageBox.Show( 20 | Window.GetWindow(owner), 21 | string.Format(str, args), 22 | "警告", 23 | MessageBoxButton.OK, 24 | MessageBoxImage.Warning); 25 | } 26 | 27 | public static void ErrBox(this FrameworkElement owner, string str, params object[] args) 28 | { 29 | MessageBox.Show( 30 | Window.GetWindow(owner), 31 | string.Format(str, args), 32 | "错误", 33 | MessageBoxButton.OK, 34 | MessageBoxImage.Error); 35 | } 36 | 37 | public static bool YesNoBox(this FrameworkElement owner, string str, params object[] args) 38 | { 39 | return MessageBox.Show( 40 | Window.GetWindow(owner), 41 | string.Format(str, args), 42 | "请选择", 43 | MessageBoxButton.YesNo, 44 | MessageBoxImage.Question) == MessageBoxResult.Yes; 45 | } 46 | 47 | public static bool? YesNoCancelBox(this FrameworkElement owner, string str, params object[] args) 48 | { 49 | var mbr = MessageBox.Show( 50 | Window.GetWindow(owner), 51 | string.Format(str, args), 52 | "请选择", 53 | MessageBoxButton.YesNoCancel, 54 | MessageBoxImage.Question); 55 | if (mbr == MessageBoxResult.Yes) 56 | return true; 57 | if (mbr == MessageBoxResult.No) 58 | return false; 59 | return null; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tablegen2/common/Util.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | using System.Threading; 6 | 7 | namespace tablegen2 8 | { 9 | internal static class Util 10 | { 11 | /// 12 | /// 获取环境目录 13 | /// 14 | public static string WorkPath 15 | { 16 | get { return System.AppDomain.CurrentDomain.BaseDirectory; } 17 | } 18 | 19 | public static string ModulePath 20 | { 21 | get { return System.Windows.Forms.Application.ExecutablePath; } 22 | } 23 | 24 | /// 25 | /// 确保此文件夹存在 26 | /// 27 | /// 文件夹路径 28 | public static void MakesureFolderExist(string dir) 29 | { 30 | if (!Directory.Exists(dir)) 31 | Directory.CreateDirectory(dir); 32 | } 33 | 34 | /// 35 | /// 打开文件夹 36 | /// 37 | /// 目录 38 | public static void OpenDir(string dir) 39 | { 40 | try 41 | { 42 | if (!System.IO.Directory.Exists(dir)) 43 | return; 44 | 45 | System.Diagnostics.Process.Start("explorer.exe", dir); 46 | } 47 | catch (System.Exception) 48 | { 49 | } 50 | } 51 | 52 | /// 53 | /// 打开某个目录并选中对应文件 54 | /// 55 | /// 文件路径 56 | public static void OpenDirFile(string path) 57 | { 58 | try 59 | { 60 | if (!System.IO.File.Exists(path) && !System.IO.Directory.Exists(path)) 61 | return; 62 | 63 | System.Diagnostics.Process.Start("explorer.exe", string.Format("/select,\"{0}\"", path)); 64 | } 65 | catch (System.Exception) 66 | { 67 | } 68 | } 69 | 70 | /// 71 | /// 获取1970到现在的天数 72 | /// 73 | /// 74 | public static int GetDayFrom1970() 75 | { 76 | DateTime tm = new DateTime(1970, 1, 1); 77 | TimeSpan ts = DateTime.Now - tm; 78 | return ts.Days; 79 | } 80 | 81 | /// 82 | /// 取得随机数 83 | /// 84 | private static Random rdm_ = new Random(Environment.TickCount); 85 | public static int GetRandom(int min, int max) 86 | { 87 | return rdm_.Next(min, max); 88 | } 89 | 90 | /// 91 | /// 计算缓冲区的Md5 92 | /// 93 | public static string MdBuffer(byte[] buffer) 94 | { 95 | StringBuilder sb = new StringBuilder(); 96 | MD5CryptoServiceProvider svr = new MD5CryptoServiceProvider(); 97 | foreach (byte b in svr.ComputeHash(buffer)) 98 | sb.Append(b.ToString("X2")); 99 | return sb.ToString(); 100 | } 101 | 102 | /// 103 | /// 计算字符串的UTF8格式Md5值 104 | /// 105 | public static string MdString(string str) 106 | { 107 | return MdBuffer(Encoding.UTF8.GetBytes(str)); 108 | } 109 | 110 | /// 111 | /// 计算文件的Md5值 112 | /// 113 | public static string MdFile(string path) 114 | { 115 | using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) 116 | { 117 | StringBuilder sb = new StringBuilder(); 118 | MD5CryptoServiceProvider svr = new MD5CryptoServiceProvider(); 119 | foreach (byte b in svr.ComputeHash(fs)) 120 | sb.Append(b.ToString("X2")); 121 | return sb.ToString(); 122 | } 123 | } 124 | 125 | public static string ToFormatLength(long length) 126 | { 127 | string s = ""; 128 | if (length < 1024) 129 | { 130 | s = String.Format("{0} KB", Math.Ceiling(length / 1024.0f)); 131 | } 132 | else if (length < 1024 * 1024) 133 | { 134 | s = String.Format("{0:N2} KB", length / 1024.0f); 135 | } 136 | else if (length < 1024 * 1024 * 1024) 137 | { 138 | s = String.Format("{0:N2} MB", length / 1024.0f / 1024.0f); 139 | } 140 | else 141 | { 142 | s = String.Format("{0:N2} MB", length / 1024.0f / 1024.0f / 1024.0f); 143 | } 144 | 145 | return s; 146 | } 147 | 148 | /// 149 | /// 删除某个目录,最大删除清理 150 | /// 151 | /// 要删除的目录 152 | /// 成功或失败 153 | public static bool RemoveDirectory(string dir) 154 | { 155 | bool r = true; 156 | 157 | if (Directory.Exists(dir)) 158 | { 159 | foreach (var s in Directory.GetFiles(dir)) 160 | { 161 | try 162 | { 163 | File.Delete(s); 164 | Thread.Sleep(1); 165 | } 166 | catch 167 | { 168 | r = false; 169 | } 170 | } 171 | 172 | foreach (var s in Directory.GetDirectories(dir)) 173 | { 174 | if (!RemoveDirectory(s)) 175 | { 176 | r = false; 177 | continue; 178 | } 179 | 180 | Directory.Delete(s); 181 | Thread.Sleep(1); 182 | } 183 | } 184 | 185 | return r; 186 | } 187 | 188 | public static bool IsStringNumber(string s) 189 | { 190 | if (string.IsNullOrEmpty(s)) 191 | return false; 192 | 193 | foreach (var c in s) 194 | { 195 | if (!char.IsNumber(c)) 196 | return false; 197 | } 198 | return true; 199 | } 200 | 201 | public static void performClick(System.Windows.Controls.Button btn) 202 | { 203 | btn.RaiseEvent(new System.Windows.RoutedEventArgs(System.Windows.Controls.Button.ClickEvent, btn)); 204 | } 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /tablegen2/layouts/common/ButtonDark.xaml: -------------------------------------------------------------------------------- 1 |  55 | -------------------------------------------------------------------------------- /tablegen2/layouts/common/ButtonDark.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace tablegen2.layouts 4 | { 5 | /// 6 | /// DarkButton.xaml 的交互逻辑 7 | /// 8 | public partial class ButtonDark : Button 9 | { 10 | public ButtonDark() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tablegen2/layouts/common/ButtonLight.xaml: -------------------------------------------------------------------------------- 1 |  57 | -------------------------------------------------------------------------------- /tablegen2/layouts/common/ButtonLight.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace tablegen2.layouts 4 | { 5 | /// 6 | /// LightButton.xaml 的交互逻辑 7 | /// 8 | public partial class ButtonLight : Button 9 | { 10 | public ButtonLight() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tablegen2/layouts/common/HelperPanel.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 24 | 25 | 27 | 28 | 29 | 30 | 31 |