python excel处理
#!/usr/bin/python # data:2018/4/20 # user:fei # -*- coding: utf-8 -*- import json import sys import time import openpyxl import json creat_data=time.strftime('%Y-%m-%d',time.localtime()) i=1 wb = openpyxl.Workbook() sheet = wb.active sheet.title = (creat_data + '-people') field = ['类型', '姓名', '用户名', '单位', '职务', '科室'] for title in field: # 写入表头 sheet.cell(row=1, column=i, value=title) i += 1 with open('C:/Users/fei/PycharmProjects/git_data/python_base/day10/json','r+',encoding='utf8') as f: load_dict = json.load(f) for line in load_dict: info=line['data'] basic_info=info['basic'] job_info=info['job'] user_type=info['account_type'] username=basic_info['real_name'] user_id=basic_info['username'] organization=job_info['organization'] position=job_info['position'][0] department=job_info['department'] all_info=[user_type,username,user_id,organization,position,department] # print(all_info) sheet.append(all_info) wb.save('test.xlsx') print('打印完成')