把文档中的数据取出并插入到excel中
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("测试完成")
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号