from xlrd import open_workbook
from xlutils.copy import copy

jsonfile=r'C:\Users\Administrator\Desktop\en.json'
jsonread=open(jsonfile,'r',encoding='UTF-8').read()
a=eval(jsonread)
textlist=[]
for d in a:
if type(a[d])==dict:
for i in a[d]:
if type(a[d][i])==dict:
for j in a[d][i]:
if type(a[d][i][j])==dict:
for k in a[d][i][j]:
if type(a[d][i][j][k])==dict:
for l in a[d][i][j][k]:
textlist.append(a[d][i][j][k][l])
else:
textlist.append(a[d][i][j][k])
else:
textlist.append(a[d][i][j])

else:
textlist.append(a[d][i])
else:
textlist.append(a[d])

excelfile=r'C:\Users\Administrator\Desktop\json.xls'
rb = open_workbook(excelfile)

#通过sheet_by_index()获取的sheet没有write()方法
rs = rb.sheet_by_index(0)

wb = copy(rb)

#通过get_sheet()获取的sheet有write()方法
ws = wb.get_sheet(0)
count=0
for e in textlist:
ws.write(count,0,e)
count+=1

wb.save(excelfile)
print("测试完成")

相关文章:

  • 2022-12-23
  • 2021-10-28
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-01-08
  • 2022-12-23
  • 2021-09-17
  • 2022-01-13
  • 2021-09-17
相关资源
相似解决方案