Skip to content

Commit 6031efa

Browse files
committed
add gui
1 parent f697eba commit 6031efa

13 files changed

+925
-0
lines changed

TableML/TableML.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableMLCompiler", "TableMLC
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableMLCompilerConsole", "TableMLCompilerConsole\TableMLCompilerConsole.csproj", "{D3A252A3-78B0-4651-AD16-C6B6A30F7326}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableMLGUI", "TableMLGUI\TableMLGUI.csproj", "{55E28E01-2E74-4809-A2EE-A566FEA5D899}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
3335
{D3A252A3-78B0-4651-AD16-C6B6A30F7326}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{D3A252A3-78B0-4651-AD16-C6B6A30F7326}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{D3A252A3-78B0-4651-AD16-C6B6A30F7326}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{55E28E01-2E74-4809-A2EE-A566FEA5D899}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{55E28E01-2E74-4809-A2EE-A566FEA5D899}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{55E28E01-2E74-4809-A2EE-A566FEA5D899}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{55E28E01-2E74-4809-A2EE-A566FEA5D899}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

TableML/TableMLGUI/ExcelHelper.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Windows.Forms;
7+
using NPOI.SS.UserModel;
8+
using TableML.Compiler;
9+
10+
namespace TableMLGUI
11+
{
12+
public class ExcelHelper
13+
{
14+
public static void UpdateAllTableSyntax()
15+
{
16+
var findPath = System.Environment.CurrentDirectory + ".\\..\\Src";
17+
//var findPath = @"e:\3dsn\plan\005ConfigTable\Src\";
18+
var files = Directory.GetFiles(findPath, "*.xls", SearchOption.AllDirectories);
19+
Console.WriteLine("开始更新{0}张Excel表", files.Length);
20+
var count = 0;
21+
foreach (string file in files)
22+
{
23+
var update = ToCSharpSyntax(file);
24+
if (update) count += 1;
25+
}
26+
Console.WriteLine("更新Excel表完成。");
27+
MessageBox.Show(string.Format("共整理{0}张表的前端字段为C#类型", count), "整理完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
28+
}
29+
30+
/// <summary>
31+
/// 替换成C#的数据类型
32+
/// </summary>
33+
/// <param name="filePath"></param>
34+
/// <returns>文件是否有改变</returns>
35+
public static bool ToCSharpSyntax(string filePath)
36+
{
37+
bool fileChange = false;
38+
IWorkbook Workbook;
39+
ISheet Worksheet;
40+
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) // no isolation
41+
{
42+
try
43+
{
44+
Workbook = WorkbookFactory.Create(file);
45+
}
46+
catch (Exception e)
47+
{
48+
throw new Exception(string.Format("无法打开Excel: {0}, 可能原因:正在打开?或是Office2007格式(尝试另存为)? {1}", filePath,
49+
e.Message));
50+
//IsLoadSuccess = false;
51+
}
52+
}
53+
Worksheet = Workbook.GetSheetAt(0);
54+
List<ICell> cells = Worksheet.GetRow(4).Cells;
55+
foreach (ICell cell in cells)
56+
{
57+
58+
if (cell.StringCellValue == "num")
59+
{
60+
cell.SetCellValue("int");
61+
fileChange = true;
62+
}
63+
64+
if (cell.StringCellValue == "str")
65+
{
66+
cell.SetCellValue("string");
67+
fileChange = true;
68+
}
69+
if (cell.StringCellValue.StartsWith("arr"))
70+
{
71+
cell.SetCellValue("string");
72+
fileChange = true;
73+
}
74+
if (cell.StringCellValue.StartsWith("ssg"))
75+
{
76+
cell.SetCellValue("string");
77+
fileChange = true;
78+
}
79+
}
80+
//文件没有改变,不保存
81+
if (!fileChange) return false;
82+
using (var memStream = new MemoryStream())
83+
{
84+
Workbook.Write(memStream);
85+
memStream.Flush();
86+
memStream.Position = 0;
87+
88+
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
89+
{
90+
var data = memStream.ToArray();
91+
fileStream.Write(data, 0, data.Length);
92+
fileStream.Flush();
93+
}
94+
}
95+
return true;
96+
}
97+
}
98+
}

TableML/TableMLGUI/MainForm.Designer.cs

Lines changed: 167 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)