1. import xlrd, json, codecs
    2. from collections import OrderedDict
    3. wb = xlrd.open_workbook('code.xlsx') # 需要修改的转换的xlsx文件
    4. convert_list = []
    5. sh = wb.sheet_by_index(0)
    6. title = sh.row_values(0) # 属性名
    7. for row_num in range(1, sh.nrows):
    8. row_v = sh.row_values(row_num) # 输出的是每一行的数据
    9. single = OrderedDict() # 有序字典
    10. for column in range(0, len(row_v)):
    11. # print(title[colnum], rowvalue[colnum])
    12. single[title[column]] = row_v[column]
    13. convert_list.append(single)
    14. with codecs.open('file.json', "w", "utf-8") as f:
    15. f.write(json.dumps(convert_list, ensure_ascii=False, indent=2) + '\n')