【python】将excel转成json

excel格式如下:

转换后如下

{"BD": 1375.0, "BE": 829.0, "BF": 3.0, "BG": 577.0, "BA": 100.0}

 

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import xlrd
import json
file = "cn.xlsx"
data = xlrd.open_workbook(file)
table = data.sheets()[0]
nrows = table.nrows
returnData = {}
for i in range(nrows):
    content = table.row_values(i)
    returnData[content[0]] = content[1]
returnJson = json.dumps(returnData)
print returnJson

 

posted @ 2018-04-26 10:30  郑立赛  阅读(5812)  评论(0编辑  收藏  举报