Skip to content

Commit d5a0636

Browse files
committed
v0.1.1 released
1 parent a1cf39c commit d5a0636

File tree

8 files changed

+77
-64
lines changed

8 files changed

+77
-64
lines changed

ExcelPatternTool.Core/DataBase/ExcelPatternToolDbContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4343

4444
}
4545
}
46+
47+
public object GetDbSet(Type entityType)
48+
{
49+
var method = this.GetType().GetMethod("Set", new Type[0]).MakeGenericMethod(entityType);
50+
return method.Invoke(this, new object[0]);
51+
}
4652
}
4753
}

ExcelPatternTool.Core/ExcelPatternTool.Core.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>0.1.0</Version>
4+
<Version>0.1.1</Version>
55
<TargetFramework>net6.0</TargetFramework>
66
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="AutoMapper" Version="11.0.1" />
1110
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.2.0" />
1211
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
1312
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">

ExcelPatternTool.Core/Helper/AutoMapperHelper.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

ExcelPatternTool/CliProcessor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ public static void Usage()
2727
Console.WriteLine(" -p PatternFile");
2828
Console.WriteLine(" 指定一个Pattern文件(Json), 作为转换的模型文件");
2929
Console.WriteLine(" -i Input");
30-
Console.WriteLine(" 指定一个Excel文件路径,此文件将作为导入数据源");
31-
Console.WriteLine(" 支持Xls或者Xlsx文件");
30+
Console.WriteLine(" 指定一个路径,或Sql连接字符串作为导入目标");
31+
Console.WriteLine(" 当指定 -s 参数为sqlserver, sqlite, mysql时,需指定为连接字符串;");
32+
Console.WriteLine(" 当指定 -s 参数为excel时,需指定为将要读取的Excel文件路径,支持Xls或者Xlsx文件");
3233
Console.WriteLine(" -o Output");
3334
Console.WriteLine(" 指定一个路径,或Sql连接字符串作为导出目标");
3435
Console.WriteLine(" 当指定 -d 参数为sqlserver, sqlite, mysql时,需指定为连接字符串;");
3536
Console.WriteLine(" 当指定 -d 参数为excel时,需指定为将要另存的Excel文件路径,支持Xls或者Xlsx文件");
3637
Console.WriteLine(" -s Source");
37-
Console.WriteLine(" 值为excel");
38+
Console.WriteLine(" 值为excel, sqlserver, sqlite或者mysql");
3839
Console.WriteLine(" -d Destination");
3940
Console.WriteLine(" 值为excel, sqlserver, sqlite或者mysql");
4041
Console.WriteLine(" -w WaitAtEnd");

ExcelPatternTool/DbProcessor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ExcelPatternTool.Core.DataBase;
2+
using ExcelPatternTool.Core.EntityProxy;
23
using ExcelPatternTool.Core.Excel.Models.Interfaces;
34
using System;
45
using System.Collections.Generic;
@@ -35,5 +36,15 @@ public static void ExportToDb(List<IExcelEntity> entities, string dbtype, string
3536
}
3637
}
3738

39+
public static List<IExcelEntity> ImportFromDb(Type entityType, string dbtype, string connectingString)
40+
{
41+
using (var dbcontext = dbContextFactory.CreateExcelPatternToolDbContext(connectingString, dbtype))
42+
{
43+
var dbset = dbcontext.GetDbSet(entityType);
44+
return ((IEnumerable<IExcelEntity>)dbset).ToList();
45+
}
46+
}
47+
48+
3849
}
3950
}

ExcelPatternTool/ExcelPatternTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>0.1.0</Version>
4+
<Version>0.1.1</Version>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<OutputType>Exe</OutputType>

ExcelPatternTool/Program.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ExcelPatternTool.Core.EntityProxy;
22
using ExcelPatternTool.Core.Excel.Models;
3+
using ExcelPatternTool.Core.Excel.Models.Interfaces;
34
using ExcelPatternTool.Core.Helper;
45
using ExcelPatternTool.Core.Patterns;
56
using ExcelPatternTool.Core.Validators;
@@ -39,8 +40,15 @@ static void Main(string[] args)
3940

4041
var op1 = new ImportOption(EntityProxyContainer.Current.EntityType, _pattern.ExcelImport.SheetNumber, _pattern.ExcelImport.SkipRow);
4142
op1.SheetName=_pattern.ExcelImport.SheetName;
42-
var result = DocProcessor.ImportFrom(CliProcessor.inputPathList.First(), op1);
43-
43+
List<IExcelEntity> result;
44+
if (CliProcessor.source=="excel")
45+
{
46+
result = DocProcessor.ImportFrom(CliProcessor.inputPathList.First(), op1);
47+
}
48+
else
49+
{
50+
result = DbProcessor.ImportFromDb(EntityProxyContainer.Current.EntityType, CliProcessor.source, CliProcessor.outputPathList.First());
51+
}
4452
ValidateProcessor.GetDataAction(result);
4553

4654
Console.WriteLine("校验完成,发现{0}个问题", ValidateProcessor.ProcessResultList.Count);

README.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
Excel表格-数据库互导工具
44

5-
## 介绍
6-
指定Pattern文件-一个规则描述的json文档,基于此规则实现Excel表格与数据库之间的导入导出,校验等功能。
5+
## 介绍
6+
指定Pattern文件-一个规则描述的json文档,基于此规则实现Excel表格与数据库之间的导入导出,校验等功能。使用场景有:Excel导入至数据库、Excel转Excel(合并,校验,规范化)、数据库导出至Excel(报表生成)等。
77

8-
## 特点
8+
## 特点
99
1. 小巧,轻量化的命令行工具
1010
2. 基于json文档的配置
1111
3. 支持Excel97-2003(xls)与Excel2007及以上(xlsx)格式
1212
4. 数据库支持SQL server、Sqlite、MySql
1313
5. 支持单元格注解,样式,公式的导出(导出至Excel)
1414
6. 内置lambda表达式和正则表达式两种校验器
1515

16-
## 更新内容
16+
## 更新内容
1717

1818
Date | Version | Content
1919
:----------: | :-----------: | :-----------
2020
V0.1.0 | 2022-7-29 | 初始版本
21-
21+
V0.1.1 | 2022-8-3 | 1. 新增数据库导入 2. 减小程序包体积
2222

2323
## 快速开始
2424

@@ -106,13 +106,46 @@ Sample2:
106106

107107
### 安装
108108

109-
不需要特别的安装,在此获取[ept.exe](https://github.com/MatoApps/ExcelPatternTool/raw/master/EPT/ept.exe),或git pull代码后`生成`可执行文件
109+
不需要特别的安装,直接运行可执行文件即可
110+
* 直接下载
111+
,在此获取[ept.exe](https://github.com/MatoApps/ExcelPatternTool/raw/master/EPT/ept.exe)
112+
113+
114+
```
115+
git clone https://github.com/MatoApps/ExcelPatternTool.git
116+
```
117+
118+
```
119+
cd .\ExcelPatternTool
120+
```
121+
```
122+
dotnet publish -p:PublishSingleFile=true -r win-x64 -c Release --self-contained true -p:EnableCompressionInSingleFile=true
123+
```
124+
125+
126+
代码后`生成`可执行文件
127+
```
128+
ExcelPatternTool\bin\Release\net6.0\win-x64\publish\ExcelPatternTool.exe
129+
```
110130

111131
### 运行
112132
1. 进入可执行文件所在目录,并运行
113133
* 若要导出至Sqlite,请确保相同目录下包含`e_sqlite3.dll`
114134
* 若要导出至SQL server,请确保相同录下包含`Microsoft.Data.SqlClient.SNI.dll`
115135

136+
参数列表:
137+
138+
参数 | 含义 | 用法
139+
:----------: | :-----------: | :-----------
140+
-p | PatternFile | 指定一个Pattern文件(Json), 作为转换的模型文件
141+
-i | Input | 指定一个路径,或Sql连接字符串作为导入目标<br>当指定 -s 参数为`sqlserver`, `sqlite`, `mysql`时,需指定为连接字符串;<br>当指定 -s 参数为`excel`时,需指定为将要读取的Excel文件路径,支持Xls或者Xlsx文件
142+
-o | Output | 指定一个路径,或Sql连接字符串作为导出目标<br>当指定 -d 参数为`sqlserver`, `sqlite`, `mysql`时,需指定为连接字符串;<br>当指定 -d 参数为`excel`时,需指定为将要另存的Excel文件路径,支持Xls或者Xlsx文件
143+
-s | Source | 值为`excel`, `sqlserver`, `sqlite`或者`mysql`
144+
-d | Destination | 值为`excel`, `sqlserver`, `sqlite`或者`mysql`
145+
-w | WaitAtEnd | 指定时,程序执行完成后,将等待用户输入退出
146+
-h | Help | 查看帮助
147+
148+
116149
导出至Sqlite的Sample
117150
```
118151
.\ept.exe -p .\sample\pattern.json -i .\sample\test.xlsx -o "Data Source=mato.db" -s excel -d sqlite
@@ -138,18 +171,6 @@ Sample2:
138171
![ss1](https://github.com/MatoApps/ExcelPatternTool/blob/master/EPT/screenshots/3.png)
139172

140173

141-
参数列表:
142-
143-
参数 | 含义 | 用法
144-
:----------: | :-----------: | :-----------
145-
-p | PatternFile | 指定一个Pattern文件(Json), 作为转换的模型文件
146-
-i | Input | 指定一个Excel文件路径,此文件将作为导入数据源<br>支持Xls或者Xlsx文件
147-
-o | Output | 指定一个路径,或Sql连接字符串作为导出目标<br>当指定 -d 参数为sqlserver, sqlite, mysql时,需指定为连接字符串;<br>当指定 -d 参数为excel时,需指定为将要另存的Excel文件路径,支持Xls或者Xlsx文件
148-
-s | Source | 值为excel
149-
-d | Destination | 值为excel, sqlserver, sqlite或者mysql
150-
-w | WaitAtEnd | 指定时,程序执行完成后,将等待用户输入退出
151-
-h | Help | 查看帮助
152-
153174
## 其他
154175
### 配置
155176

@@ -204,6 +225,11 @@ public override Dictionary<string, ValidateConvention> InitConventions()
204225
return defaultConventions;
205226
}
206227
```
228+
## Todo
229+
230+
- [x] 从数据库导入
231+
- [ ] 校验过程的忽略与单独使用
232+
- [ ] ept带UI版本(WPF)
207233

208234

209235
## 工具

0 commit comments

Comments
 (0)