Let excel express complex JSON format and export excel to json. Can be used on windows & *nix.
- setup config files
config.json
{
"xlsx": {
"head": 1, // head of the excel(set "head":2 if first line is commnet and second line is real head).
"src": "./excel/**/[^~$]*.xlsx", // .xlsx files that going to be exported. glob style.
"dest": "./json", // directory of exported .json files.
"arraySeparator":"," // separtor of array.
}
}
- Exceute
export.bat
and./excel/*.xlsx
files will be exported to./json
directory.
id | weapon | flag | nums#[] | words#[] | bools#[] | objs#{} | obj_arr#[{}] |
---|---|---|---|---|---|---|---|
123 | shield | true | 1,2 | hello,world | true,true | a:123;b:45 | a:1;b:"hi",a:2;b:"hei" |
456 | sword | false | 3,5,8 | oh god | false,true | a:11;b:22 | a:1;b:"hello" |
Result:
[{
"id": 123,
"weapon": "shield",
"flag": true,
"nums": [1, 2],
"words": ["hello", "world"],
"bools": [true, true],
"objs": {
"a": 123,
"b": 45
},
"obj_arr": [
{"a": 1,"b": "hi"},
{"a": 2,"b": "hei"}
]
}, {
"id": 456,
"weapon": "sword",
"flag": false,
"nums": [3, 5, 8],
"words": ["oh god"],
"bools": [false, true],
"objs": {
"a": 11,
"b": 22
},
"obj_arr": [
{"a": 1,"b": "hello"}
]
}]
- number
- boolean
- string
- object
- number-array
- boolean-array
- string-array
- object-array
- string:
column_name#string
。 - number:
column_name#number
。 - bool:
column_name#bool
。 - basic type (string,number,bool):we can also leave it blank(automake type aware).
- number/boolean/string array:
column_name#[]
。 - object:
column_name#{}
。 - object array:
column_name#[{}]
。
Inspiring by a clojure project excel-to-json 。
- Type
node index.js -h
int cmd window to show help; - Use
,
to separate array values by default(we can set it in config file). - Use
;
to separate object properties。 - Only support for .xlsx format for now(do not support .xls format).
- In order to make it portable, I put .\bin\node.exe(used by export.bat) into project.