11 KiB
11 KiB
In [8]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/党建出版社2025.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, 2).value
dict1['sex'] = sheet.cell(n, 4).value
dict1['unit'] = '党建出版社'
dict1['birth'] = sheet.cell(n,3).value
dict1['phone'] = sheet.cell(n,5).value
person[code] = dict1
filename = 'data/党建出版社2025.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')ok
In [1]:
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):
code = int(sheet.cell(n, 1).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n, 4).value
dict1['birth'] = sheet.cell(n,3).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':'编号卡'}
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 [1]:
import json
import datetime
import csv
from datetime import date
import my_module as My
filename = 'data/党建出版社2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/marks_20250530.csv'
re_ta = My.get_result(filename,dict1)
filename = 'data/result_党建出版社2025.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))60
In [2]:
import json
import time
import my_module as My
#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']
filename = 'data/result_党建出版社2025.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
#print(k)
if v['sex'] == '男':
sex = 'M'
else:
sex = 'F'
if 'bmi' in v.keys():
#bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]
bmi_data = v['bmi']['成绩']
data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}
dict2[k]['bmi'] = {}
dict2[k]['bmi']['成绩'] = bmi_data
dict2[k]['bmi']['score'] = My.cal_bmi(data1)
for item_en in list_item:
if item_en in v.keys():
data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}
#print(k,v['name'])
dict2[k][item_en]['score'] = My.cal_score(data1)
#print(k,v[item_en]['成绩'],cal_score(data1))
filename = f'data/result_党建出版社2025.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') ok!
In [3]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_党建出版社2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/党建出版社2025.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
list2.append(str(k).rjust(5,'0'))
list2.append(v['name'])
list2.append(dict2[k]['sex'])
list2.append(dict2[k]['unit'])
if 'bmi' in v.keys():
height = v['bmi']['成绩'].split(',')[0]
weight = v['bmi']['成绩'].split(',')[1]
list2.append(height)
list2.append(weight)
else:
list2.append('')
list2.append('')
for item in items:
if item in v.keys():
list2.append(v[item]['成绩'])
elif item =='name':
list2.append(v[item])
else:
list2.append('')
list1.append(list2)
filename = 'data/党建出版社测试情况表2025.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]: