文件是个json文件 内容为:

python小练习之读取文件写入excel

导入excel后的格式为

python小练习之读取文件写入excel

 

屡一下思路 一步步怎么实现:

1 首先需要读取json文件 然后将读取的内容转为字典

2 将excel的列名写入一个list中 然后遍历执行写入excel

3 注意到字典的values内容只有4个元素 需要另加入 学号 ,总分和平均分元素;

   所以我们首先将字典的key值  遍历放入对应的values中,然后在计算每个valuse的总分个平均分

4 写入excel

 

代码实现:

import xlwt
 
book = xlwt.Workbook()
'sheet1')
'utf-8')
0)
res = eval(f.read())
 
'平均分']
0
in title:
0,lie,i)
1
1
in res.items():
 
0, j) //遍历字典 并将key值加入value中
 
1 //控制行  第二次写入 行数是1   第0行已经写入标题  
in res.values():
4]
3  
  x.append(score_sum)
  x.append(score_avg)
0 // 控制列 
in x:
    sheet.write(hang,lie1,lis)
1
1
'score.xls')

 

相关文章:

  • 2022-12-23
  • 2021-11-11
  • 2021-11-05
  • 2021-09-17
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2022-02-19
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案