python实现json转excel

import json

import xlwt

a = json.load(open("haha.json", encoding='utf8'))
title = list(set([j for i in a for j in i]))
book = xlwt.Workbook()
sheet = book.add_sheet('Sheet1', cell_overwrite_ok=True)  # 添加一个sheet页
for i in range(len(title)):  # 循环列
    sheet.write(0, i, title[i])  # 将title数组中的字段写入到0行i列中
for i, it in enumerate(a):
    for j, k in enumerate(title):
        sheet.write(1 + i, j, it[k])
book.save('haha.xls')

猜你喜欢

转载自www.cnblogs.com/weiyinfu/p/9103118.html