7.2 KiB
7.2 KiB
In [1]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/报名登记表142人.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
code = int(sheet.cell(n, 1).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 3).value
dict1['sex'] = sheet.cell(n, 4).value
dict1['unit'] = sheet.cell(n, 2).value
dict1['birth'] = 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 [2]:
import json
filename = 'data/北京党校.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
dict2 = {}
#if dict1['sex'] =='男':
# sex = 1
dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}
list1.append(dict2)
json_data = json.dumps(list1,ensure_ascii=False, indent=4)
# 将 json 数据写入文件
with open("data/data_北京党校.json", "w",encoding = 'utf-8') as file:
file.write(json_data)
print('ok')ok
In [4]:
import openpyxl
import json
filename = 'data/北京党校.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
wb = openpyxl.load_workbook('data/北京党校手工数据.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}
dict3 = {1:10,2:11,3:7,4:2,5:6,6:3,7:1}
sheet = wb.active
data1 =list(sheet.values)
del data1[0]
list1 = []
for item in data1:
code = int(item[0])
list1.append((496534,code,item[2],item[1],'2023-10-15','2023-10-15 14:00:00'))
print(list1)[(496534, 6, 5, 32, '2023-10-15', '2023-10-15 14:00:00'), (496534, 39, 5, 12, '2023-10-15', '2023-10-15 14:00:00'), (496534, 105, 5, 22, '2023-10-15', '2023-10-15 14:00:00'), (496534, 136, 5, 20, '2023-10-15', '2023-10-15 14:00:00'), (496534, 110, 5, 53, '2023-10-15', '2023-10-15 14:00:00'), (496534, 144, 5, 11, '2023-10-15', '2023-10-15 14:00:00'), (496534, 87, 5, 45, '2023-10-15', '2023-10-15 14:00:00'), (496534, 71, 5, 22, '2023-10-15', '2023-10-15 14:00:00'), (496534, 153, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 158, 5, 23, '2023-10-15', '2023-10-15 14:00:00'), (496534, 150, 5, 28, '2023-10-15', '2023-10-15 14:00:00'), (496534, 140, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 138, 5, 35, '2023-10-15', '2023-10-15 14:00:00'), (496534, 137, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 377, 5, 59, '2023-10-15', '2023-10-15 14:00:00'), (496534, 131, 5, 55, '2023-10-15', '2023-10-15 14:00:00'), (496534, 76, 5, 52, '2023-10-15', '2023-10-15 14:00:00'), (496534, 14, 5, 25, '2023-10-15', '2023-10-15 14:00:00'), (496534, 88, 5, 29, '2023-10-15', '2023-10-15 14:00:00'), (496534, 115, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 78, 5, 57, '2023-10-15', '2023-10-15 14:00:00'), (496534, 103, 5, 67, '2023-10-15', '2023-10-15 14:00:00'), (496534, 148, 5, 10, '2023-10-15', '2023-10-15 14:00:00'), (496534, 54, 5, 57, '2023-10-15', '2023-10-15 14:00:00'), (496534, 35, 5, 21, '2023-10-15', '2023-10-15 14:00:00'), (496534, 42, 5, 39, '2023-10-15', '2023-10-15 14:00:00'), (496534, 45, 5, 50, '2023-10-15', '2023-10-15 14:00:00'), (496534, 95, 5, 36, '2023-10-15', '2023-10-15 14:00:00'), (496534, 122, 5, 51, '2023-10-15', '2023-10-15 14:00:00'), (496534, 74, 5, 27, '2023-10-15', '2023-10-15 14:00:00'), (496534, 63, 5, 62, '2023-10-15', '2023-10-15 14:00:00'), (496534, 100, 5, 20, '2023-10-15', '2023-10-15 14:00:00'), (496534, 162, 5, 30, '2023-10-15', '2023-10-15 14:00:00'), (496534, 43, 5, 50, '2023-10-15', '2023-10-15 14:00:00'), (496534, 149, 5, 49, '2023-10-15', '2023-10-15 14:00:00'), (496534, 127, 5, 16, '2023-10-15', '2023-10-15 14:00:00'), (496534, 62, 5, 21, '2023-10-15', '2023-10-15 14:00:00'), (496534, 40, 5, 10, '2023-10-15', '2023-10-15 14:00:00'), (496534, 53, 5, 24, '2023-10-15', '2023-10-15 14:00:00')]
In [ ]: