【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