您的位置:首页 > 其它

转化Csv,excel到语言相关的文件

2015-08-09 19:30 489 查看
代码地址:https://github.com/neoliang/const-data


const-data

const-data is a free, open source tool, the target of this tool are:1.convert csv or excel to simple language specified data format.2.generate language speicfied reading codes


csv
or excel format

the first three rows are fixed
the first rows describes data which will be ignored in converting
the second row describes data name in this columnthe third row describes data type in this column: validate types are:
a. int
b. float
c. string
d. json
e. comment: the comment type of column will be ignored in converting
f. empty: the type of column of empty type will be intexamples:
id触发类型触发id奖励备注其它
idtrigger_typetrigger_idrewardcommentextra
stringintjsoncommentfloat
1piece26{"yellow":2}泥土消除奖励0
2piece27{"diamond:1}钻石消除奖励10.5
a. the type of id-column is int because it's empty


converting
csv file to lua file

#convert one csv file
#in root dir
cd convert
python ./convert.py -file ../testdata/reward.csv -out_dir ../testdata -if csv -of lua

#convert csv files in dir
python ./convert.py -dir ../testdata -out_dir ../testdata -if csv -of lua


converting
csv file to json file

#convert one csv file
#in root dir
cd convert
python ./convert.py -file ../testdata/reward.csv -out_dir ../testdata -if csv -of json

#convert csv files in dir
python ./convert.py -dir ../testdata -out_dir ../testdata -if csv -of json


converting
excel to other files

1.the command line is almost same as convert csv excpe the option -if is excel2.you must install xlrd using pip as following:
pip install xlrd


command
line usage:

usage: python ./convert.py -if input_format -of output_format -file input_file -out_dir lua_dir
python ./convert_csv_to_lua.py -if input_format -of output_format -dir csv_dir -out_dir lua_dir

options:
-if:    input file format : csv or excel
-of:    output file format lua,json
-dir:     convert files in dir
-file:    convert file
-out_dir: the dir of output files
-h print: this message


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: