一、图形化界面实现使用tkinter工具包(见代码)。

二、生成可执行程序步骤

1、安装Pyinstaller工具。打开cmd命令窗口执行pip install pyinstaller。在 PyInstaller 模块安装成功之后,在 Python 的安装目录下的 Scripts(D:\Python\Python36\Scripts) 目录下会增加一个 pyinstaller.exe 程序,接下来就可以使用工具将 Python 程序生成 EXE 程序了。

2、将文件examkit.py复制到Scripts(D:\Python\Python36\Scripts) 目录下;打开cmd,找到该路径上图路径D:\Python\Python36\Scripts执行pyinstaller -F  examkit.py

cmd找路径笔记:f:进入F盘,dir查看当前位置包含的所有子文件夹和子文件,cd文件夹名即为进入该文件夹。

#!/usr/bin/env python

# -*- encoding: utf-8 -*-

'''

@文件    :examkit.py

@说明    :考务工作处理excel文件工具包

@时间    :2021/05/03 09:03:51

@作者    :侃侃

@版本    :3.8

'''

from tkinter import *

import tkinter.filedialog

import pandas as pd 

import os

from tkinter import messagebox

#按照文件所包含的专业新建不同专业的工作表

def creatfilebyschool(filepath,filename):  

    scoresinfo=pd.read_excel(filepath,dtype=str)

    #获取专业列所有数值,包括重复的

    schools=scoresinfo['函授站']

    #获取去重后的专业并转化为list方便读取数据,set函数是一个无序不重复的元素集,list为[],set为{}

    nschools=list(set(schools))

    #获取专业的个数,即需要创建工作表的个数

    filenums=len(nschools)

    #根据专业数量,创建对应个数的工作表,工作表的名称以专业命名

    for i in range(0,filenums,1): 

       schoolpath=filepath.replace(filename,"")+list(nschools)[i]+".xlsx"

       df=pd.DataFrame()

       df.to_excel(schoolpath)



def splitbyschool(filepath,filename):

    #1、创建各专业文件

    creatfilebyschool(filepath,filename)

    print("文件路径"+filepath)

    print("文件名字"+filename)

    scores=pd.read_excel(filepath,dtype=str)#一张表读出来为dataframe类型

    grouped=scores.groupby("函授站")#按照专业分组

    schools=scores['函授站']#获取专业列所有数值,包括重复的

    nschools=list(set(schools))#获取去重后的专业并转化为list方便读取数据,set函数是一个无序不重复的元素集,list为[],set为{}

    #2、分别将各专业从分组后的集合中取出.get_group("专业名称"),然后专业名称与文件名称比对,配对后写入对应专业文件

    dir=filepath.replace("/"+filename,"")#获取文件所在的根目录,即文件夹目录

    print("文件夹路径"+dir)

    for i in range(0,len(nschools),1):

        school=grouped.get_group(nschools[i])

        #遍历文件夹下面的所有文件

        for root_dir,sub_dir,files in os.walk(r'' + dir):#遍历目录下的根目录,子目录,所有文件

            # 对文件列表中的每一个文件进行处理,如果文件名字是以‘xlxs’结尾就

            # 认定为是一个excel文件,当然这里还可以用其他手段判断,比如你的excel

            # 文件名中均包含‘res’,那么if条件可以改写为

            # if file.endswith('xlsx') and 'res' in file:

            for file in files:

                if file==nschools[i]+'.xlsx':

                   school.to_excel(filepath.replace(filename,"")+nschools[i]+".xlsx",index=False,encoding="utf-8")

def mymessage():

    messagebox.showinfo("提示","拆分完成")

def open():

    filepath=tkinter.filedialog.askopenfilename()#打开文件,获取文件地址

    splitbyschool(filepath,filepath.split('/')[-1])#按照函授站拆分

    mymessage()#拆分完成后弹出对话框,提示拆分完成

def popupmenu(event):

     mainmenu.post(event.x_root,event.y_root)

#按钮一的注意事项

def note1():

    msg1.config(text="本按钮用于毕业前毕业后大补考登分单拆分,将表格按照函授站拆成多个电子表格,表头要求必须有表头为“函授站”的列名。")

root= Tk()

root.title('考务工作常用工具-放鸭江上')

root.geometry('700x500') # 这里的乘号不是 * ,而是小写英文字母 x

note=""

#控件分布设置

btn1 = Button(root, text='1、按照函授站拆分表格', command=open)

btn2 = Button(root, text='<---注意事项', fg='#CD5C5C',command=note1)



btn3 = Button(root, text='2、按照专业拆分表格', command="")

btn4 = Button(root, text='<---注意事项', fg='#CD5C5C',command="")



btn5 = Button(root, text='3、成绩纵向格式转横向格式', command="")

btn6 = Button(root, text='<---注意事项', fg='#CD5C5C',command="")



btn1.place(x=70, y=20, relwidth=0.25, relheight=0.1)

btn2.place(x=460, y=20, relwidth=0.25, relheight=0.1)



btn3.place(x=70, y=100, relwidth=0.25, relheight=0.1)

btn4.place(x=460, y=100, relwidth=0.25, relheight=0.1)



btn5.place(x=70, y=180, relwidth=0.25, relheight=0.1)

btn6.place(x=460, y=180, relwidth=0.25, relheight=0.1)



msg1 = Message(root,text="",font=('Arial', 20),fg='#CD5C5C',relief=RAISED,justify=LEFT)

msg1.place(x=70,y=260,relheight=0.4,width=560)

root.mainloop()