日常工作中遇到一些Excel表格的数据,需要转换成json格式的字符串,怎么处理呢?可以使用这个工具:excel2json
下载地址:https://github.com/neil3d/excel2json/releases
用cmd进入文件解压所在的地址,敲入命令
excel2json --excel E:\a\student.xlsx --json E:\a\student.json --header 1 --array true
意思是 把E:\a\student.xlsx这个文件,转成E:\a\student.json这个,头有1行 转换成数组格式的。
student.xlsx的格式是这样:头就是第一行。目前只支持转换.xlsx文件。
各参数解释:
-e, --excel Required. input excel file path.
-j, --json export json file path.
-s, --sql export SQL file path.
-p, --csharp export C# data struct code file path.
-h, --header Required. number lines in sheet as header.
-c, --encoding (Default: utf8-nobom) export file encoding.
-l, --lowcase (Default: False) convert filed name to lowcase.
-a, --array (Default: False) export as array, otherwise as dict object.
导出的student.json内容如下:
[{
"StringID": "p1",
"vzh_rCN": "最流行",
"vus": "Charts",
"vth": "แผนภูมิ",
"vms": "Carta",
"vin": "Tangga lagu",
},
{
"StringID": "p2",
"vzh_rCN": "1个月",
"vus": "1 month",
"vth": "1 เดือน",
"vms": "1 bulan",
"vin": "1 bulan",
}]
然后将这个json文件后缀改为js,在代码里面加:
也可以用网站直接转:https://tableconvert.com/