白日依山尽,黄河入海流。欲穷千里目,更上一层楼。 -- 唐·王之涣

Shell脚本实现excel到json的格式转化

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": "宣武区"
            },
....

公众号: DailyJobOps DailyJobOps
作者

Colin

发布于

2015-05-15

许可协议