Skip to content

Commit 4cea1be

Browse files
committed
Merge branch 'dev'
2 parents 8db0e43 + 6ffb2f3 commit 4cea1be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4774
-63490
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*.sln.docstates
88

99
# Build results
10+
packages/
11+
.vs/
1012
[Dd]ebug/
1113
[Dd]ebugPublic/
1214
[Rr]elease/

CSDefineGenerator.cs

-76
This file was deleted.

ChangeLog.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# excel2json Change Log
22

3+
## Ver 1.2.0
4+
5+
* 注意:必须先关闭 Excel 软件,再执行转换。因为 Excel 软件会锁定文件,导致其他程序无法读取
6+
* 升级 ExcelDataReader 组件,现在支持所有 Excel 文件格式( 2003 *.xls, 2007 *.xlsx)
7+
* 默认导出表中所有Sheet,格式为:{ SheetName: { SheetOBject } }
8+
* 在行对象中添加ID字段
9+
* 去除 SQL 和 C# 结构体代码生成功能
10+
311
## Ver 1.1.1
412

513
* GUI模式:增加了 [Reimport] 按钮,在设置项改变之后,方便重新导入数据;

Docs/ExampleData.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"NPC": {
3+
"BS001": {
4+
"ID": "BS001",
5+
"Name": "鬼道士",
6+
"AssetName": "BS001",
7+
"HP": 100,
8+
"Attack": 15,
9+
"Defence": 0,
10+
"ActPoints": 5,
11+
"ActSpeed": 1.5,
12+
"Hit": 8,
13+
"Dodge": 0,
14+
"Critical": 8,
15+
"BS001": "BS001"
16+
},
17+
"BS002": {
18+
"ID": "BS002",
19+
"Name": "钟馗",
20+
"AssetName": "BS002",
21+
"HP": 352,
22+
"Attack": 22,
23+
"Defence": 3,
24+
"ActPoints": 32,
25+
"ActSpeed": 4,
26+
"Hit": 3,
27+
"Dodge": 4,
28+
"Critical": 2,
29+
"BS002": "BS002"
30+
},
31+
"BS003": {
32+
"ID": "BS003",
33+
"Name": "",
34+
"AssetName": "BS003",
35+
"HP": 332,
36+
"Attack": 3,
37+
"Defence": 44,
38+
"ActPoints": 432,
39+
"ActSpeed": 4,
40+
"Hit": 3,
41+
"Dodge": 4,
42+
"Critical": 2,
43+
"BS003": "BS003"
44+
}
45+
},
46+
"Item": {
47+
"WP001": {
48+
"ID": "WP001",
49+
"Name": "倚天剑",
50+
"AssetName": "ICON01",
51+
"WP001": "WP001"
52+
},
53+
"WP002": {
54+
"ID": "WP002",
55+
"Name": "屠龙刀",
56+
"AssetName": "ICON02",
57+
"WP002": "WP002"
58+
}
59+
}
60+
}

Docs/ExampleData.xlsx

-350 Bytes
Binary file not shown.

ExcelLoader.cs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.IO;
3+
using System.Data;
4+
using ExcelDataReader;
5+
6+
namespace excel2json {
7+
/// <summary>
8+
/// 将 Excel 文件(*.xls 或者 *.xlsx)加载到内存 DataSet
9+
/// </summary>
10+
class ExcelLoader {
11+
private DataSet mData;
12+
13+
// TODO: add Sheet Struct Define
14+
15+
public ExcelLoader(string filePath, int headerRow) {
16+
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) {
17+
// Auto-detect format, supports:
18+
// - Binary Excel files (2.0-2003 format; *.xls)
19+
// - OpenXml Excel files (2007 format; *.xlsx)
20+
using (var reader = ExcelReaderFactory.CreateReader(stream)) {
21+
// Use the AsDataSet extension method
22+
// The result of each spreadsheet is in result.Tables
23+
var result = reader.AsDataSet(createDataSetReadConfig(headerRow));
24+
this.mData = result;
25+
}
26+
}
27+
28+
if (this.Sheets.Count < 1) {
29+
throw new Exception("Excel file is empty: " + filePath);
30+
}
31+
}
32+
33+
public DataTableCollection Sheets {
34+
get {
35+
return this.mData.Tables;
36+
}
37+
}
38+
39+
private ExcelDataSetConfiguration createDataSetReadConfig(int headerRow) {
40+
var tableConfig = new ExcelDataTableConfiguration() {
41+
// Gets or sets a value indicating whether to use a row from the
42+
// data as column names.
43+
UseHeaderRow = true,
44+
45+
// Gets or sets a callback to determine whether to include the
46+
// current row in the DataTable.
47+
FilterRow = (rowReader) => {
48+
return rowReader.Depth > headerRow - 1;
49+
},
50+
};
51+
52+
return new ExcelDataSetConfiguration() {
53+
// Gets or sets a value indicating whether to set the DataColumn.DataType
54+
// property in a second pass.
55+
UseColumnDataType = true,
56+
57+
// Gets or sets a callback to obtain configuration options for a DataTable.
58+
ConfigureDataTable = (tableReader) => { return tableConfig; },
59+
};
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)