Skip to content

Dev upgrade libs #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
# Code Generator
此工具主要用于将[Excel模板](template)文档转换为数据库结构、初始数据的sql脚本及多语言资源代码。

此工具主要用于将[Excel 模板](template)文档转换为数据库结构、初始数据的 sql 脚本及多语言资源代码。

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

- DDL - 生成数据库结构代码,支持 Mysql/SQLServer/SQLite
- DML - 生成初始数据的 sql 代码
- MSG - 生成多语言资源代码,支持 Android/IOS/JSON/Java/.NET

## 安装
**Mac/Linux 用户**

### Mac/Linux 用户

```sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.sh)"
```

> 将以上命令粘贴至终端。

**Windows 用户**
### Windows 用户

```ps1
iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/excel-code-generator/code-generator/master/install.ps1'))
```
> 将以上命令粘贴至PowerShell。

**更新**
> 将以上命令粘贴至 PowerShell。

### 更新

```sh
cg update
```

> Windows/Mac/Linux 均相同。

## 在Docker中使用
## 在 Docker 中使用

```sh
docker pull yanglibing/code-generator
docker run --rm -it yanglibing/code-generator
```

## 参数说明
```

```text
用法:cg command file [options]
Commands:
Commands:
update 检查并更新到最新版本
ddl.mssql 生成SqlServer数据库结构SQL脚本(.ddl)
ddl.mysql 生成MySql数据库结构SQL脚本(.ddl)
Expand All @@ -53,34 +64,37 @@ Options:
-s,--sheets <names> 要处理的Excel Sheet名,默认除"#"开头外的全部Sheet
-v,--version 打印版本信息

示例:
示例:
cg msg.json 001.xlsx
cg msg.resx 001.xlsx --sheets Sheet1 Sheet2 Sheet5

帮助:
帮助:
cg ddl.mysql --help 显示数生成据库结构的更多帮助信息
cg dml --help 显示生成初始数据的更多帮助信息
cg msg.json --help 显示生成国际化资源的更多帮助信息

通过 cg command --help 查看指定命令的详细说明。

---
Code Generator v4.2.1
Code Generator v4.3.0
By https://yanglb.com
```

## 用法示例

```sh
# 生成 MySql 数据库结构脚本
cg ddl.mysql database.xlsx --engine myisam

# 生成 JSON 多语言资源
cg msg.json msg.xlsx
```
> Excel模板请参考 [template](template)

> Excel 模板请参考 [template](template)

## 升级说明
4.x版本不兼容老版本的命令行参数,但Excel模板在所有版本下均可正常使用。

4.x 版本不兼容老版本的命令行参数,但 Excel 模板在所有版本下均可正常使用。

## License

Expand Down
25 changes: 19 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,42 @@

<groupId>org.yanglb</groupId>
<artifactId>code-generator</artifactId>
<version>4.2.1</version>
<version>4.3.0</version>
<packaging>jar</packaging>

<dependencies>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>3.11</version>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.32</version>
<version>2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
<version>20231013</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.24.2</version>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -74,4 +80,11 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>
15 changes: 8 additions & 7 deletions src/main/java/com/yanglb/codegen/core/reader/BaseReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
Expand Down Expand Up @@ -185,23 +186,23 @@ private boolean isReadable(String sheetName) {
*/
public String getCellStringValue(XSSFCell cell) {
String result = null;
int type = cell.getCellType();
if(type == Cell.CELL_TYPE_FORMULA) type = cell.getCachedFormulaResultType();
if(type == Cell.CELL_TYPE_BLANK) return null;
if(type == Cell.CELL_TYPE_ERROR) {
CellType type = cell.getCellType();
if(type == CellType.FORMULA) type = cell.getCachedFormulaResultType();
if(type == CellType.BLANK) return null;
if(type == CellType.ERROR) {
return "#VALUE!";
}

switch(type) {
case Cell.CELL_TYPE_BOOLEAN:
case BOOLEAN:
result = String.valueOf(cell.getBooleanCellValue());
break;

case Cell.CELL_TYPE_STRING:
case STRING:
result = cell.getStringCellValue();
break;

case Cell.CELL_TYPE_NUMERIC:
case NUMERIC:
{
if(cell.getCellStyle().getDataFormat() == DataFormatType.FORMAT_DATE) {
Date date = cell.getDateCellValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.yanglb.codegen.utils.StringUtil;
import java.util.HashMap;
import java.util.List;

import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
Expand All @@ -43,7 +45,7 @@ protected HashMap<String, String> onReader(XSSFSheet sheet) {
XSSFRow xssfRow = sheet.getRow(row);
String key = this.getCellStringValue(xssfRow.getCell(this.startColNo));
// key不为空时添加到Map中
if(xssfRow.getCell(this.startColNo).getCellType() == XSSFCell.CELL_TYPE_BLANK
if(xssfRow.getCell(this.startColNo).getCellType() == CellType.BLANK
|| StringUtil.isNullOrEmpty(key)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
Expand Down Expand Up @@ -78,16 +80,16 @@ protected TableModel onReader(XSSFSheet sheet) throws CodeGenException {
throw new CodeGenException(String.format("error: sheet(%s), row(%d), col(%d)",
sheet.getSheetName(), rowNo, colNo));
}
if(cell.getCellType() != XSSFCell.CELL_TYPE_BLANK
&& cell.getCellType() != XSSFCell.CELL_TYPE_ERROR) {
if(cell.getCellType() != CellType.BLANK
&& cell.getCellType() != CellType.ERROR) {
allBlank = false;
}
String value = this.getCellStringValue(cell);

// 第一行为KEY
if(rowNo == this.startRowNo) {
if(StringUtil.isNullOrEmpty(value)
|| cell.getCellType() ==XSSFCell.CELL_TYPE_BLANK
|| cell.getCellType() ==CellType.BLANK
|| "-".equals(value)) {
// 空白/忽略的列无视
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/yanglb/codegen/utils/Infos.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

public class Infos {
public static final String Name = "Code Generator";
public static final String Version = "4.2.1";
public static final String Copyright = "Copyright 2015-2023 yanglb.com All Rights Reserved.";
public static final String Version = "4.3.0";
public static final String Copyright = "Copyright 2015-2024 yanglb.com All Rights Reserved.";
public static final String Author = "me@yanglb.com";
public static final String Website = "https://yanglb.com";
public static final String Repository = "https://github.com/excel-code-generator/code-generator";
Expand Down