Skip to content

Commit 040e771

Browse files
authored
Merge pull request #3 from excel-code-generator/dev-upgrade-libs
Dev upgrade libs
2 parents 9d11f99 + e658331 commit 040e771

File tree

6 files changed

+67
-35
lines changed

6 files changed

+67
-35
lines changed

README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
11
# Code Generator
2-
此工具主要用于将[Excel模板](template)文档转换为数据库结构、初始数据的sql脚本及多语言资源代码。
2+
3+
此工具主要用于将[Excel 模板](template)文档转换为数据库结构、初始数据的 sql 脚本及多语言资源代码。
34

45
## 主要功能
5-
* DDL - 生成数据库结构代码,支持 Mysql/SQLServer/SQLite
6-
* DML - 生成初始数据的sql代码
7-
* MSG - 生成多语言资源代码,支持 Android/IOS/JSON/Java/.NET
6+
7+
- DDL - 生成数据库结构代码,支持 Mysql/SQLServer/SQLite
8+
- DML - 生成初始数据的 sql 代码
9+
- MSG - 生成多语言资源代码,支持 Android/IOS/JSON/Java/.NET
810

911
## 安装
10-
**Mac/Linux 用户**
12+
13+
### Mac/Linux 用户
14+
1115
```sh
1216
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.sh)"
1317
```
18+
1419
> 将以上命令粘贴至终端。
1520
16-
**Windows 用户**
21+
### Windows 用户
22+
1723
```ps1
1824
iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.ps1'))
1925
```
20-
> 将以上命令粘贴至PowerShell。
2126

22-
**更新**
27+
> 将以上命令粘贴至 PowerShell。
28+
29+
### 更新
30+
2331
```sh
2432
cg update
2533
```
34+
2635
> Windows/Mac/Linux 均相同。
2736
28-
## 在Docker中使用
37+
## 在 Docker 中使用
38+
2939
```sh
3040
docker pull yanglibing/code-generator
3141
docker run --rm -it yanglibing/code-generator
3242
```
3343

3444
## 参数说明
35-
```
45+
46+
```text
3647
用法:cg command file [options]
37-
Commands:
48+
Commands:
3849
update 检查并更新到最新版本
3950
ddl.mssql 生成SqlServer数据库结构SQL脚本(.ddl)
4051
ddl.mysql 生成MySql数据库结构SQL脚本(.ddl)
@@ -53,34 +64,37 @@ Options:
5364
-s,--sheets <names> 要处理的Excel Sheet名,默认除"#"开头外的全部Sheet
5465
-v,--version 打印版本信息
5566
56-
示例:
67+
示例:
5768
cg msg.json 001.xlsx
5869
cg msg.resx 001.xlsx --sheets Sheet1 Sheet2 Sheet5
5970
60-
帮助:
71+
帮助:
6172
cg ddl.mysql --help 显示数生成据库结构的更多帮助信息
6273
cg dml --help 显示生成初始数据的更多帮助信息
6374
cg msg.json --help 显示生成国际化资源的更多帮助信息
6475
6576
通过 cg command --help 查看指定命令的详细说明。
6677
6778
---
68-
Code Generator v4.2.1
79+
Code Generator v4.3.0
6980
By https://yanglb.com
7081
```
7182

7283
## 用法示例
84+
7385
```sh
7486
# 生成 MySql 数据库结构脚本
7587
cg ddl.mysql database.xlsx --engine myisam
7688

7789
# 生成 JSON 多语言资源
7890
cg msg.json msg.xlsx
7991
```
80-
> Excel模板请参考 [template](template)
92+
93+
> Excel 模板请参考 [template](template)
8194
8295
## 升级说明
83-
4.x版本不兼容老版本的命令行参数,但Excel模板在所有版本下均可正常使用。
96+
97+
4.x 版本不兼容老版本的命令行参数,但 Excel 模板在所有版本下均可正常使用。
8498

8599
## License
86100

pom.xml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,42 @@
66

77
<groupId>org.yanglb</groupId>
88
<artifactId>code-generator</artifactId>
9-
<version>4.2.1</version>
9+
<version>4.3.0</version>
1010
<packaging>jar</packaging>
1111

1212
<dependencies>
1313
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
1414
<dependency>
1515
<groupId>commons-cli</groupId>
1616
<artifactId>commons-cli</artifactId>
17-
<version>1.4</version>
17+
<version>1.8.0</version>
1818
</dependency>
1919
<dependency>
2020
<groupId>org.apache.commons</groupId>
2121
<artifactId>commons-text</artifactId>
22-
<version>1.10.0</version>
22+
<version>1.12.0</version>
2323
</dependency>
2424
<dependency>
2525
<groupId>org.apache.poi</groupId>
2626
<artifactId>poi-excelant</artifactId>
27-
<version>3.11</version>
27+
<version>5.3.0</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.yaml</groupId>
3131
<artifactId>snakeyaml</artifactId>
32-
<version>1.32</version>
32+
<version>2.0</version>
3333
</dependency>
3434
<!-- https://mvnrepository.com/artifact/org.json/json -->
3535
<dependency>
3636
<groupId>org.json</groupId>
3737
<artifactId>json</artifactId>
38-
<version>20200518</version>
38+
<version>20231013</version>
39+
</dependency>
40+
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
41+
<dependency>
42+
<groupId>org.apache.logging.log4j</groupId>
43+
<artifactId>log4j-core</artifactId>
44+
<version>2.24.2</version>
3945
</dependency>
4046
</dependencies>
4147
<build>
@@ -74,4 +80,11 @@
7480
</plugin>
7581
</plugins>
7682
</build>
83+
<repositories>
84+
<repository>
85+
<id>maven_central</id>
86+
<name>Maven Central</name>
87+
<url>https://repo.maven.apache.org/maven2/</url>
88+
</repository>
89+
</repositories>
7790
</project>

src/main/java/com/yanglb/codegen/core/reader/BaseReader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.List;
3232
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
3333
import org.apache.poi.ss.usermodel.Cell;
34+
import org.apache.poi.ss.usermodel.CellType;
3435
import org.apache.poi.xssf.usermodel.XSSFCell;
3536
import org.apache.poi.xssf.usermodel.XSSFSheet;
3637
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -185,23 +186,23 @@ private boolean isReadable(String sheetName) {
185186
*/
186187
public String getCellStringValue(XSSFCell cell) {
187188
String result = null;
188-
int type = cell.getCellType();
189-
if(type == Cell.CELL_TYPE_FORMULA) type = cell.getCachedFormulaResultType();
190-
if(type == Cell.CELL_TYPE_BLANK) return null;
191-
if(type == Cell.CELL_TYPE_ERROR) {
189+
CellType type = cell.getCellType();
190+
if(type == CellType.FORMULA) type = cell.getCachedFormulaResultType();
191+
if(type == CellType.BLANK) return null;
192+
if(type == CellType.ERROR) {
192193
return "#VALUE!";
193194
}
194195

195196
switch(type) {
196-
case Cell.CELL_TYPE_BOOLEAN:
197+
case BOOLEAN:
197198
result = String.valueOf(cell.getBooleanCellValue());
198199
break;
199200

200-
case Cell.CELL_TYPE_STRING:
201+
case STRING:
201202
result = cell.getStringCellValue();
202203
break;
203204

204-
case Cell.CELL_TYPE_NUMERIC:
205+
case NUMERIC:
205206
{
206207
if(cell.getCellStyle().getDataFormat() == DataFormatType.FORMAT_DATE) {
207208
Date date = cell.getDateCellValue();

src/main/java/com/yanglb/codegen/core/reader/impl/HashMapReaderImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.yanglb.codegen.utils.StringUtil;
2020
import java.util.HashMap;
2121
import java.util.List;
22+
23+
import org.apache.poi.ss.usermodel.CellType;
2224
import org.apache.poi.xssf.usermodel.XSSFCell;
2325
import org.apache.poi.xssf.usermodel.XSSFRow;
2426
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -43,7 +45,7 @@ protected HashMap<String, String> onReader(XSSFSheet sheet) {
4345
XSSFRow xssfRow = sheet.getRow(row);
4446
String key = this.getCellStringValue(xssfRow.getCell(this.startColNo));
4547
// key不为空时添加到Map中
46-
if(xssfRow.getCell(this.startColNo).getCellType() == XSSFCell.CELL_TYPE_BLANK
48+
if(xssfRow.getCell(this.startColNo).getCellType() == CellType.BLANK
4749
|| StringUtil.isNullOrEmpty(key)) {
4850
continue;
4951
}

src/main/java/com/yanglb/codegen/core/reader/impl/TableReaderImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.HashMap;
2525
import java.util.List;
2626
import java.util.Map;
27+
28+
import org.apache.poi.ss.usermodel.CellType;
2729
import org.apache.poi.xssf.usermodel.XSSFCell;
2830
import org.apache.poi.xssf.usermodel.XSSFRow;
2931
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -78,16 +80,16 @@ protected TableModel onReader(XSSFSheet sheet) throws CodeGenException {
7880
throw new CodeGenException(String.format("error: sheet(%s), row(%d), col(%d)",
7981
sheet.getSheetName(), rowNo, colNo));
8082
}
81-
if(cell.getCellType() != XSSFCell.CELL_TYPE_BLANK
82-
&& cell.getCellType() != XSSFCell.CELL_TYPE_ERROR) {
83+
if(cell.getCellType() != CellType.BLANK
84+
&& cell.getCellType() != CellType.ERROR) {
8385
allBlank = false;
8486
}
8587
String value = this.getCellStringValue(cell);
8688

8789
// 第一行为KEY
8890
if(rowNo == this.startRowNo) {
8991
if(StringUtil.isNullOrEmpty(value)
90-
|| cell.getCellType() ==XSSFCell.CELL_TYPE_BLANK
92+
|| cell.getCellType() ==CellType.BLANK
9193
|| "-".equals(value)) {
9294
// 空白/忽略的列无视
9395
continue;

src/main/java/com/yanglb/codegen/utils/Infos.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
public class Infos {
1919
public static final String Name = "Code Generator";
20-
public static final String Version = "4.2.1";
21-
public static final String Copyright = "Copyright 2015-2023 yanglb.com All Rights Reserved.";
20+
public static final String Version = "4.3.0";
21+
public static final String Copyright = "Copyright 2015-2024 yanglb.com All Rights Reserved.";
2222
public static final String Author = "me@yanglb.com";
2323
public static final String Website = "https://yanglb.com";
2424
public static final String Repository = "https://github.com/excel-code-generator/code-generator";

0 commit comments

Comments
 (0)