Files
jupyter/体测单位/西藏.ipynb
T
2023-05-28 15:42:01 +08:00

2.5 KiB

人员信息导入

In [3]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/健康体质检测人员名单(西藏销售).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}

for n in range(2, sheet.max_row+1):
    if sheet.cell(n,1).value is not None:
        code = int(sheet.cell(n, 1).value)
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 2).value
        if sheet.cell(n, 3).value ==1:
            sex = '男'
        else:
            sex = '女'
        dict1['sex'] = sex
        birth = str(sheet.cell(n, 4).value).split()[0]
        dict1['birth'] = birth
        dict1['unit'] = sheet.cell(n, 6).value
        if sheet.cell(n,5).value is not None:
            dict1['phone'] = str(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 [ ]: