Git Product home page Git Product logo

excel2json's Introduction

excel2json

Copyright (C) 2013 by Hojin Choi [email protected]

Excel2json is a converting script that supports to manage well structured excel data to json format.

You can freely redistribute this product with A-CUP-OF-BEER License (See source code)

USAGE

ADD SOME HINTS TO YOUR EXCEL FILE FOR JSON

There are four types of object, which can be handled by this script.

Simple Object

If you have an excel file, very simple one like this.

A B C D E
1 Initial data
2 Name Value
3 coins 1000
3 golds 0

And, Let's give a hint for the script, which awares A Column's '#' mark.

A B C D E
1 Initial data
2 Name Value
3 #initdata{} $key $value inserted!
4 coins 1000
5 golds 0

In the above example, you can get this JSON file

{
	"initdata" : {
		"coins" : 1000,
		"golds" : 0
	}
}

Objects in Object

Above example explains plain value object, now if you want an object which has objects as the key/value pairs, you can use "{{}}" suffix instead of "{}"

A B C D E
1 Buildings
2 Name Color Width Height
3 #buildings{{}} $key color width height
4 barrack blue 200 200
5 mine yellow 200 100
6 gas red 100 100
7 townhall black 200 200

And, this yields

{
	"buildings" : {
		"barrack" : {
			"color": "blue",
			"width": 200,
			"height": 200
		},
		"mine" : {
			"color": "yellow",
			"width": 200,
			"height": 100
		},
		"gas": {
			"color": "red",
			"width": 100,
			"height": 100
		},
		"townhall": {
			"color": "black",
			"width": 200,
			"height": 100
		}
	}
}			

Arrays in Object

This type of object has nested value as an array, see this example!

A B C D E
1 Required coins of buildings
2 #reqcoins{[]} barrack mine gas
3 100 100 100
4 500 500 500
5 1000 1000 1000
6 1500

As you can see, the suffix of #reqcoins is "{[]}", this gives hints for constructing vertical array. The result is

{
	"reqcoins" : {
		"barrack" : [100, 500, 1000, 1500 ],
		"mine" : [ 100, 500, 1000 ],
		"gas"  : [ 100, 500, 1000 ]
	}
}

Object Array

The last format of compound data is an array which contains objects, the suffix "[{}]"

A B C D E
1 Shop
2 #shop[{}] name price category
3 blade 100 attack
4 dagger 200 attack
5 shield 100 defese

And this yields

{
	"shop" : [
		{
			"name": "blade",
			"price" : 100,
			"category" : "attack"
		},
		{
			"name": "dagger",
			"price": 200,
			"category": "attack"
		},
		{
			"name": "shield",
			"price": 100,
			"category": "defense"
		}
	]
}

Array Value (Tip)

Magic field suffix "[]" of object description line introduce array value.

A B C D E
1 Shop
2 #inventory[{}] type attrib[] dur
3 blade oil, diamond 100
4 dagger sapphire 150
5 shield diamond,sapphire,rune 200

The "attrib[]" field name terminates with "[]", which indicates attrib key has array value. so, the result will be like this.

{
	"inventory" : [
		{
			"type": "blade",
			"attrib": [ "oil", "diamond" ],
			"dur": 100
		},
		{
			"type": "dagger",
			"attrib": [ "sapphire" ],
			"dur": 150
		},
		{
			"type": "shield",
			"attrib": [ "diamond", "sapphire", "rune" ],
			"dur": 200
		}
	]
}

Some technical marks

'!' prefixed sheet name

You can insert '!' mark before a sheet name which will not be considered to be parsed. For e.g. '!Samples', '!Test' or '!Templates'.

RUN Excel2Json.js

".js" extension files are associated with WSCRIPT.EXE (Windows already has this program!), you can easily run the script by double click!

You may also make your own start script, like an 'excel2json.bat' with which you can run the script specifying excel files and output folder name as the arguments.

MKDIR output
WSCRIPT.EXE Excel2Json.js file1.xlsx file2.xlsx product

HOWTO-WORK

Internally, CSV format is used to parse excel files.

By clicking the script in explorer:

0. Make 'output' folder (mkdir output)
1. Run the script in a folder without any argument (by clicking)
2. The script searches the folder for all excel files with extension .xls, .xlsx.
3. All the sheets in the excel file are converted to CSV files.
4. The CSV files are stored temporary folders with suffix (.$$$)
6. Parse the CSV files and make json files into the 'output' folder.
7. All the temporary folders will be removed with their contents (csv files)

By running WSCRIPT.EXE Excel2Json.js file1.xlsx file2.xlsx product:

1. All the proceess is same with above.
2. But it does not search the directory for excel files.
3. And use the 'product' directory instead of 'output' for its result.

excel2json's People

Contributors

bryant1410 avatar coolengineer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

excel2json's Issues

Problem With Encoding

Thank you for this scripts , its amazing but I have issue with arabic letters as json returns arabic letters as questions marks " ????????? "

사용관련 오류입니다.

해당 스크립트가 있는 폴더에 엑셀파일을 같이 놓고
스크립트를 실행하면
'경로를 찾을수 없습니다.' 라고 경고가 뜨고
확인 버튼을 누르면

행: 480
문자: 3
오류: 경로를 찾을 수 없습니다.
코드: 800A004C
원본: Microsoft JScript 런타임 오류

라는 에러 박스가 나타 납니다.
여기서 확인버튼을 누르면

Windows Script Host 실행에 실패하였습니다. (0x80020102)

라는 에러 메세지가 나타나고 끝나네요..

Object Array가 비정상적으로 파싱됩니다.

샘플 엑셀을 변환해보면 #reqcoins{[]}가 다음과 같이 저장됩니다.
환경은 오피스 2013입니다.

"reqcoins": {
    "barrack": [
        100,
        500,
        1000,
        1500,
        2000,
        2500,
        0,
        "상점",
        "이름",
        "name",
        "blade",
        "dagger",
        "thorn_dagger",
        "mail",
        0,
        "초기 인벤토리",
        "이름",
        "type",
        "blade",
        "thorn_dagger",
        "mail",
        0,
        0,
        "$key",
        "michael",
        "tobby",
        "tony",
        "gump"
    ],

thx

喝杯白酒,交个朋友!

String type conversion error

If excel is a String type number, such as "0200", it will be "200" in the final result, even if I set the type to String in excel, the reason is in line 637 of the source code: "if (typeof (value) == "string" && isFinite (value)) return Number (value); "If the type is String and finally converted to Number, you want to modify

잘 쓰고 있습니다. 사용법 문의 드려도 될까요?

게임 데이터 관리할 때 잘 쓰고 있습니다. 고맙습니다.

그리고, 한 가지 여쭤봐도 될까요?

안될 것 같긴 한데...

{"A" : [
{"B" : 0},
{"B" : 1}]}

이런 식으로 잘 쓰고 있긴 한데, 이번에 데이터 구조를 좀 바꾸자고 해서 내놓은게

{"A" : [
{"B" : [
{"C": 0, "D": 0},
{"C": 1, "D": 2}]},
{"B" : [
{"C": 0, "D": 0},
{"C": 1, "D": 2}]}]}

이런 식으로 바꿔달라고 하네요.

이걸 excel2json 으로 변환 가능하게 Excel 파일을 만들 수 있을까요?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.