2.2 KiB
2.2 KiB
In [2]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/天津石化员工检测花名册 (20221014).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
code = sheet.cell(n, 6).value
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 3).value
dict1['sex'] = sheet.cell(n, 4).value
dict1['unit'] = sheet.cell(n, 1).value
dict1['sub_unit'] = sheet.cell(n, 2).value
dict1['id_num'] = sheet.cell(n,5).value
person[code] = dict1
filename = 'data/天津石化人员名单.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')ok
In [ ]: