title: shell script to convert excel to json
date: 2015-05-15 11:24:01 +0800
comments: true
category: Linux
tags: linux
Requirement
there are some excel files need to convert to Json format.
include Json level one and level two
and for excel files, you need to refer to some example files from
https://github.com/opscolin/ShellScripts/tree/master/Excel2Json
Get script
wget https://github.com/opscolin/ShellScripts/blob/master/Excel2Json/Excel2Json.sh
Usage
bash Excel2Json.sh LevelOne.xlsx > LevelOne.txt
bash Excel2Json.sh 2 LevelTwo.xlsx > LevelTwo.txt
or you cat get usage by
[root@localtest /tmp ]# bash Excel2Json.sh
====================================================
Usage:
#convert Level one
Excel2Json.sh LevelOne.xlsx > LevelOne.txt
#convert Level two
Excel2Json.sh 2 LevelTwo.xlsx > LevelTwo.txt
====================================================
Example
## level one
[root@localtest liuchao]# bash Excel2Json.sh LevelOne.csv
[
{
"id":1,
"name":"北京"
},
{
"id":2,
"name":"陕西"
},
{
"id":3,
"name":"河北"
},
]
# level two
[root@localtest liuchao]# bash Excel2Json.sh 2 LevelTwo.csv
[
{
"id": 1,
"name": "北京",
"List": [
{
"id": 1,
"name": "东城区"
},
{
"id": 2,
"name": "西城区"
},
{
"id": 3,
"name": "崇文区"
},
{
"id": 4,
"name": "宣武区"
},
....