Excel spreadsheet turn Json data structure

Excel spreadsheet turn Json data structure

Removed several items, each guide table tools are difficult to use giant, slow, unspoken rules and more, poor scalability, easy to debug. Sqlite, Json, Lua, Xml have used a variety of formats.

for example:

Most tools do not support the guide table parse the text of the array, as they are abnormal rude to resolve an array of algorithms, nothing more than a Split (value, ","), when your text array no comma, everything is OK, commas appear once analysis result error, but the program is still running, until the game read error, you can realize a problem.

Type combination is not normally Table I. These tools do not support the type of combination between, for example, an array of integers, an array of hashes like. Some support for an array of integers, but it is not bound to an array of integers and two types, but defines a single integer array type, a little more complicated when it is desired structure can not be achieved or even not supported, such as arrays embedded sets of arrays.

Error can not be located, the error messages output barely read, planning even more helpless.

No type safety, when a field name configuration table is modified, the program may be completely unaware until the game to read configuration error.

data structure

On my personal best data structure data format is Json.

Sqlite client unfriendly, most clients are not familiar with SQL statements. As the configuration data, the advantages of relational database is not obvious, if the data query requires complex SQL statements, this data structure design itself is wrong, if only simple SQL queries, why not direct data Key-Value structure? In addition, Sqlite you need to use a special database software, and can not be viewed directly in the IDE or text editor.

Lua -like structure with Json, but it has two problems, 1. Is not easy to distinguish between arrays and hashes, 2. For as data structures, application range is relatively narrow, Json than Lua famous too, Json third-party parsing library than Lua and more much that we are much more receptive to Json rather than Lua.

Xml too much extra data reading with respect to Json not intuitive.

Json structure is simple, most text editors can highlight content, numerous third-party parsing library, a wide range of popular, front and rear end are acceptable.

Ease of use

I've seen a guide table overhead spent 1 hour, so that no one dares to try to export Excel, this went on for a year, the situation is not the end of this project is cold, but I re-implement a tool and completely it parsing format, new analytical procedures to export all Excel in just 10 seconds.

I have seen Excel configuration is very cumbersome, many unspoken rules, when you configure a new table, you must refer to an old table, or else you do not know how to fill.

A useful tool guide table

Due to the recent return to hand travel industry, so would like to achieve a efficiency, scalability, ease of use, safety are relatively OK guide sheet vehicles.

Format (for details see Demo)

//  已支持的格式
bool        布尔值
number      数值
string      字符串
list        数组
dict        哈希
type        自定义结构

//  格式定义
bool b;
number n;
string s;
[number] n_list;                            //  数值数组    list<number> n_list;
{number} n_dict;                            //  数组哈希    dict<number> d_dict;
<number n, string s> type;                  //  自定义结构  struct {
                                            //                  number n;
                                            //                  string s;
                                            //              } type;

//  类型组合
[[number]]  n_n_list;                       //  数组嵌套数组
{[number]}  n_n_dict;                       //  哈希嵌套数组
<[number] n_list, {number} n_dict> type;    //  数据格式如下:
                                            //  struct {
                                            //      list<number> n_list;
                                            //      dict<number> n_dict;
                                            //  } type;

Error positioning (for details see Demo)

//  打印错误文件,行,列,出错原因
C:\Github\xlsx2json>export.py
> 异常: C:\Github\xlsx2json/in/cfg_2.xlsx | 5:2 | [bool]值错误 "
> ---Export End---

Security (for details see Demo)

//  输出指定语言的数据结构(当前只支持C++和C#)
//  可通过Json库解析到对应的数据结构
var test = Json.From<config.Test>("test.json");
var n = test.n;
var s = test.s;

End

Executable file: export.py

Operating environment: Python3.0

Run dependence: openpyxl

Guide table configuration (export.py file):

#   Json输入目录
JSON_I = os.getcwd() + "/in/"
#   Json输出目录
JSON_O = os.getcwd() + "/out/"
#   结构化输出目录
STRUCT_O = os.getcwd() + "/out/config.cs"
#   命名空间
NAMESPACE = "config"

Github Portal

Guess you like

Origin www.cnblogs.com/mmc1206x/p/12536306.html