1.准备工作

  1. python 2.7 安装
  2. 安装xlrd -- pip install xlrd

2. 直接上代码

import xlrd
from collections import OrderedDict
import json
import codecs

wb = xlrd.open_workbook('file.xlsx')

convert_list = []
sh = wb.sheet_by_index(0)
title = sh.row_values(0)
for rownum in range(1, sh.nrows):
    rowvalue = sh.row_values(rownum)
    single = OrderedDict()
    for colnum in range(0, len(rowvalue)):
        print(title[colnum], rowvalue[colnum])
        single[title[colnum]] = rowvalue[colnum]
    convert_list.append(single)
    
j = json.dumps(convert_list)

with codecs.open('file.json',"w","utf-8") as f:
    f.write(j)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2021-09-06
  • 2021-10-17
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-05-06
相关资源
相似解决方案