Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
neil3d committed Feb 3, 2019
2 parents 8db0e43 + 6ffb2f3 commit 4cea1be
Show file tree
Hide file tree
Showing 49 changed files with 4,774 additions and 63,490 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*.sln.docstates

# Build results
packages/
.vs/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
Expand Down
76 changes: 0 additions & 76 deletions CSDefineGenerator.cs

This file was deleted.

8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# excel2json Change Log

## Ver 1.2.0

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

## Ver 1.1.1

* GUI模式:增加了 [Reimport] 按钮,在设置项改变之后,方便重新导入数据;
Expand Down
60 changes: 60 additions & 0 deletions Docs/ExampleData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"NPC": {
"BS001": {
"ID": "BS001",
"Name": "鬼道士",
"AssetName": "BS001",
"HP": 100,
"Attack": 15,
"Defence": 0,
"ActPoints": 5,
"ActSpeed": 1.5,
"Hit": 8,
"Dodge": 0,
"Critical": 8,
"BS001": "BS001"
},
"BS002": {
"ID": "BS002",
"Name": "钟馗",
"AssetName": "BS002",
"HP": 352,
"Attack": 22,
"Defence": 3,
"ActPoints": 32,
"ActSpeed": 4,
"Hit": 3,
"Dodge": 4,
"Critical": 2,
"BS002": "BS002"
},
"BS003": {
"ID": "BS003",
"Name": "",
"AssetName": "BS003",
"HP": 332,
"Attack": 3,
"Defence": 44,
"ActPoints": 432,
"ActSpeed": 4,
"Hit": 3,
"Dodge": 4,
"Critical": 2,
"BS003": "BS003"
}
},
"Item": {
"WP001": {
"ID": "WP001",
"Name": "倚天剑",
"AssetName": "ICON01",
"WP001": "WP001"
},
"WP002": {
"ID": "WP002",
"Name": "屠龙刀",
"AssetName": "ICON02",
"WP002": "WP002"
}
}
}
Binary file modified Docs/ExampleData.xlsx
Binary file not shown.
62 changes: 62 additions & 0 deletions ExcelLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.IO;
using System.Data;
using ExcelDataReader;

namespace excel2json {
/// <summary>
/// 将 Excel 文件(*.xls 或者 *.xlsx)加载到内存 DataSet
/// </summary>
class ExcelLoader {
private DataSet mData;

// TODO: add Sheet Struct Define

public ExcelLoader(string filePath, int headerRow) {
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) {
// Auto-detect format, supports:
// - Binary Excel files (2.0-2003 format; *.xls)
// - OpenXml Excel files (2007 format; *.xlsx)
using (var reader = ExcelReaderFactory.CreateReader(stream)) {
// Use the AsDataSet extension method
// The result of each spreadsheet is in result.Tables
var result = reader.AsDataSet(createDataSetReadConfig(headerRow));
this.mData = result;
}
}

if (this.Sheets.Count < 1) {
throw new Exception("Excel file is empty: " + filePath);
}
}

public DataTableCollection Sheets {
get {
return this.mData.Tables;
}
}

private ExcelDataSetConfiguration createDataSetReadConfig(int headerRow) {
var tableConfig = new ExcelDataTableConfiguration() {
// Gets or sets a value indicating whether to use a row from the
// data as column names.
UseHeaderRow = true,

// Gets or sets a callback to determine whether to include the
// current row in the DataTable.
FilterRow = (rowReader) => {
return rowReader.Depth > headerRow - 1;
},
};

return new ExcelDataSetConfiguration() {
// Gets or sets a value indicating whether to set the DataColumn.DataType
// property in a second pass.
UseColumnDataType = true,

// Gets or sets a callback to obtain configuration options for a DataTable.
ConfigureDataTable = (tableReader) => { return tableConfig; },
};
}
}
}
Loading

0 comments on commit 4cea1be

Please sign in to comment.