西南大学秘书部审表器源码
2022-05-12
这个代码含金量有一点点高,全部看懂,可以说python字符处理毕了一半的业
如果有缘你打开了这篇博客,想必你必定是花钱了的,还不如找到我,我给你讲解一下(如果你有看不懂的话)
贴一张运行截图(贴的是领导的版本)
检测结果:
import openpyxl import datetime import re from string import digits #检验两个班级组成是否相同 def compareclass(classup,overclass): brick = classup.split(";") brick1 = overclass.split(";") im = '' il = '' for uu in brick: if uu in overclass: im = '' else: return "nook" break for uuu in brick1: if uuu in classup: il = '' else: return "nook" break #将班级组成格式化为标准处理格式 def classrealmaker(nian,quan,ji,ber): if str(nian) in quan: #是否包含 ‘21’ #print("包含21") Nclassup = quan.replace(str(nian),ji) brick1 = Nclassup.split(";") #分割 #print(brick1) brick=[] for oo in brick1: if(ji in oo): brick.append(oo) #brick = Nclassup.split(";") nonumber = [] for a in brick: demo = str.maketrans('', '', digits) #去数字初始化 nonum = a.translate(demo) nonumber.append(nonum) #添加至去数字数组 brickclear = list(set(nonumber)) #print(brickclear) classtrue="" for d in brickclear: #print(d) qi = d.replace('班','') qia = qi.replace(")","\)") qian = qia.replace("(","\(") ree = qian + '([\s\S].?)班' result = re.findall(ree , Nclassup) #正则匹配 n = "" for m in result: n = n + m + "、" classtrue = classtrue + ber + qi + n[:-1] +"班;" last = classtrue[:-1].replace("(师)","(师范)") #print(last) return last #核心代码,一次处理到位 def allcheck(line,year,filename): workbook = openpyxl.load_workbook(filename) #返回一个workbook数据类型的值 sheet = workbook['反馈表'] # 获取指定 (反馈表) 表 #print('当前表格大小:' + sheet.dimensions) # 获取表格的尺寸大小 sheet = workbook.active #表者 numer = str(eval("sheet['B" + str(line) + "']").value) #print("此表所属:"+ numer) #classname classname = str(eval("sheet['I" + str(line) + "']").value) #print("课程名称:"+ classname) #老师所属学院 family = str(eval("sheet['H" + str(line) + "']").value) #print("师属学院:" + family) #老师 teacher = str(eval("sheet['G" + str(line) + "']").value) #print("老师姓名:" + teacher) #time time = str(eval("sheet['D" + str(line) + "']").value) #print("听课时间:"+ time) #听课节数 classnumber = str(eval("sheet['E" + str(line) + "']").value) #print("听课节数:"+ classnumber) #授课地点 place = str(eval("sheet['F" + str(line) + "']").value) #print("授课地点:"+ place) #班级组成 classup = str(eval("sheet['J" + str(line) + "']").value) #print("班级组成:" + classup) #电话号码检测 numberlength1 = len(str(eval("sheet['U" + str(line) + "']").value)) numberlength2 = len(str(eval("sheet['W" + str(line) + "']").value)) if (numberlength1 == 11 & numberlength2 == 11): #print("电话号码:合格") oooooooo = 1 else: oooooooo = 1 #print("电话号码:未及格") #听课小组检测 benum = sheet['s4'].value if (benum == '听课2组'): oooooooo = 1 #print("听课小组:合格") else: oooooooo = 1 #print("听课小组:未及格") #课程反馈检测 #print("课程反馈:" + sheet['R4'].value) #打印R4的值(课程反馈) length = len(sheet['R4'].value) if (length < 60): oooooooo = 1 #print("课程反馈:未及格") #print("课程反馈详细:" + sheet['R4'].value) if (length >= 60): oooooooo = 1 #print("课程反馈:合格") #读取总表 workbook = openpyxl.load_workbook('总.xlsx') # 返回一个workbook数据类型的值 sheet = workbook['sheet1'] # 获取指定 (反馈表) 表 sheet = workbook.active cell = sheet['H'] #根据H列(老师姓名),获取总行数 for a in cell: #print(a.value) #总表所有老师的姓名 if (str(a.value) == teacher): #print(a) #a 的格式 <Cell 'sheet1'.H10732> hang = str(a) #a字典转化为字符串 row = hang[16:-1] #从a截取行数 #print("\n\n\n总表行数:" + row) ret = 0 #初始化相似度分数 #课程名称 classname1 = eval("sheet['F" + str(row) + "']") #转换为字典模式 if (classname1.value == classname): oooooooo = 1 #print("课程名称:"+ classname1.value + "-----------经检测后吻合") ret = ret + 1 else : oooooooo = 1 #print("课程名称:"+ classname1.value) #老师所属学院 teacherhome = eval("sheet['J" + str(row) + "']") #转换为字典模式 if (teacherhome.value == family): #print('师属学院:'+ teacherhome.value+ "-----------经检测后吻合") ret = ret + 1 else : oooooooo = 1 #print("师属学院:" + teacherhome.value) #老师名称 #print("老师姓名:"+ teacher +"-----------经检测后吻合") ret = ret + 1 #时间 time1 = eval("sheet['C" + str(row) + "']") #转换为字典模式 date = time[4:-3] #日期格式为2022/03/04 截取后面 ‘/03/04’ 的部分 date1 = '2022' + date #加上年份 date2 = date1.replace("/",'') #替换 '/' 为空白 weekday = datetime.datetime.strptime(date2, "%Y%m%d").weekday() + 1 if(time1.value == str(weekday)): #print("听课时间:星期" + time1.value + '-----------经检测后吻合') ret = ret + 1 else: oooooooo = 1 #print("听课时间:星期" + time1.value) #第几节 classnumber1 = eval("sheet['D" + str(row) + "']") #转换为字典模式 classnum=classnumber.replace("第",'') if (classnumber1.value == classnum): #print("听课节数:" + classnumber1.value + '-----------经检测后吻合') ret = ret + 1 else : oooooooo = 1 #print("听课节数:" + classnumber1.value) #地点 Rplace = eval("sheet['K" + str(row) + "']") Rplace = Rplace.value.replace("-0","-") if(Rplace == place): #print("授课地点:" + place+ '-----------经检测后吻合') ret = ret +1 else: oooooooo = 1 #print("听课地点:"+ Rplace) #班级组成 Rclassup = eval("sheet['N" + str(row) + "']") #转换为字典模式 quan = Rclassup.value #print(quan) i = -10 while(i < 10): nian = year + i #21 ji = '20' + str(nian) + '级' #2021级 ber = '20' + str(nian) #2021 if ji in quan: #print("包含2021级") #如果包含 2021级 全部换为21 quan = quan.replace(ji,str(nian)) if str(ber) in quan: #如果包含 2021 全部换为21 oooooooo = 1 #print("包含2020") quan = quan.replace(str(ber),str(nian)) i = i+1 #print(quan) Fresult = '' i = -10 while(i < 10): nian = year + i #21 ji = '20' + str(nian) + '级' #2021级 ber = '20' + str(nian) #2021 ''' 下面三行是处理 21 类型的函数,上面的函数已经全部被换成了 21 型 ''' if str(nian) in quan: #print("包含20") last = classrealmaker(nian,quan,ji,ber) Fresult = Fresult + last + ";" i = i+1 overclass = Fresult[:-1] compareclass(classup,overclass) if (compareclass(classup,overclass) != "nook"): #print("匹配OK") ret = ret + 1 #print("班级组成:" + overclass + '-----------经检测后吻合') else: oooooooo = 1 #print("班级组成:" + overclass ) #课程有效时间 usetime = eval("sheet['E" + str(row) + "']") #转换为字典模式 #print("有效时间:" + usetime.value) #相似度 #print('当前匹配指数:' + str(ret)) #print(ret) if(ret == 7): #print("合格的表------" + '此表对应行数:' + str(row)) rew = 'T' return rew break else: oooooooo = 1 #print("失败的表") filename = input('待检测文件名:') minnum = int(input('从第几行开始:')) maxnum = input('到第几行结束:') print('\n\n') #line = 5 year = 22; #allcheck(line,year,filename) while minnum <= int(maxnum) : checkresult = allcheck(minnum,year,filename) if (checkresult == 'T'): break #print("第【" + str(minnum) + "】行表合格") else: print("第【" + str(minnum) + "】行表不合格") minnum = minnum +1 print("\n\n\n\n\n报告:检测完毕") i = 0 while(1 > 0): i = i+1
发表评论: