对照名单统计青年大学习完成的情况[图形界面]~解压运行

https://github.com/aleryxiao/checkQNDXXtoExcel

(包含源码和Release包)

链接: https://pan.baidu.com/s/1pXbmWk5jbnfrHTYzdiKp9w?pwd=ntjs 提取码: ntjs 

 (Release包链接)

源代码(main.py):

import pandas as pd
import re
import os
import time

from PySide6.QtWidgets import QApplication,QMainWindow,QFileDialog
from gui import Ui_MainWindow

class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()
        # 使用ui文件导入定义界面类
        self.ui = Ui_MainWindow()
        # 初始化界面
        self.ui.setupUi(self)
        self.ui.iB.clicked.connect(self.input)
        self.ui.oB.clicked.connect(self.output)
        self.ui.rB.clicked.connect(self.calc)

        self.iFilePath=[]
        self.oFilePath=""
        self.className="F2103302"
        self.ui.cT.setText(self.className)

    def input(self):
        self.iFilePath=QFileDialog.getOpenFileNames(caption="选择输入文件(可多选)",filter="表格文件(*.xlsx;*.xls)")[0]  # 起始目录
        self.ui.iT.setText((self.iFilePath[0])[:self.iFilePath[0].rfind('/')]) #第一个文件所在的文件夹

    def output(self):
        self.oFilePath=QFileDialog.getOpenFileName(caption="选择输出文件",filter="表格文件(*.xlsx;*.xls)")[0]  # 起始目录
        self.ui.oT.setText(self.oFilePath)

    def calc(self):
        if self.iFilePath and self.oFilePath:
            self.ui.rT.setText("Running...")
            self.className=self.ui.cT.text()
            try:
                self.ui.rT.setText("Start Processing Files")
                self.processFile()
            except Exception as E:
                self.ui.rT.setText("Run Error")
        else:
            self.ui.rT.setText("Not Ready To Run")

    def processFile(self):
        i = 0
        aStart=time.time()
        for filepath in self.iFilePath:
            i += 1
            start = time.time()
            doneList = []  # 完成名单
            rowList = []  # 需要导入列表的数字
            rd = pd.read_excel(filepath, sheet_name="原始数据",usecols=["团支部", "姓名/学号"])
            data = rd.values
            for info in data:
                if info[0] == self.className:
                    # print(info[1])
                    x = re.sub('[0-9’!"#$%&\'()*+,-./:;<=>?@,。?★、…【】《》?“”‘’![\\]^_`{|}~\s]+', "", info[1])
                    # print(x)
                    if x:
                        doneList.append(x)
            # print(doneList)

            rd = pd.read_excel(self.oFilePath,usecols=["姓名"])  # 获取姓名列
            NameList = rd["姓名"].tolist()
            # print(NameList)
            for name in NameList:
                if name in doneList:
                    rowList.append(1)
                else:
                    rowList.append(0)
            # print(rowList)

            writeData(self.oFilePath, rowList, ctimeYMD(filepath))
            self.ui.rT.setText(f"表格{i}处理完毕,用时{time.time()-start}秒")
        
        self.ui.rT.setText(f"{i}个文件已经处理完毕,用时{time.time()-aStart}秒")

def ctimeYMD(file):
    from datetime import datetime
    date_of_created = datetime.strptime(time.ctime(os.path.getctime(
        file)), "%a %b %d %H:%M:%S %Y")  # Convert string to date format
    return ("{}.{}.{}".format(str(date_of_created.year)[2:], str(date_of_created.month), str(date_of_created.day)))

def writeData(file, result, name):
    op = pd.read_excel(file)
    # print(result)
    times = 0
    n = name
    while True:
        try:
            op.insert(3, n, result)  # 1表示插入列的位置(索引), 'd'是列标题
            break
        except Exception as E:
            times += 1
            n = name + '('+str(times)+')'
    op.style.applymap(lambda x: 'background-color:yellow' if x ==
                      0 else "background-color:white").to_excel(file, index=False)


app = QApplication([])
mainw = MainWindow()
mainw.show()
app.exec()

图形界面:

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'untitledDwOOqm.ui'
##
## Created by: Qt User Interface Compiler version 6.4.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QMetaObject,QRect)
from PySide6.QtWidgets import (QLabel, QLineEdit, QPushButton, QTextBrowser, QWidget)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(636, 203)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.iB = QPushButton(self.centralwidget)
        self.iB.setObjectName(u"iB")
        self.iB.setGeometry(QRect(380, 50, 221, 31))
        self.oB = QPushButton(self.centralwidget)
        self.oB.setObjectName(u"oB")
        self.oB.setGeometry(QRect(380, 95, 221, 31))
        self.iT = QTextBrowser(self.centralwidget)
        self.iT.setObjectName(u"iT")
        self.iT.setGeometry(QRect(30, 50, 331, 31))
        self.oT = QTextBrowser(self.centralwidget)
        self.oT.setObjectName(u"oT")
        self.oT.setGeometry(QRect(30, 95, 331, 31))
        self.rB = QPushButton(self.centralwidget)
        self.rB.setObjectName(u"rB")
        self.rB.setGeometry(QRect(30, 144, 101, 31))
        self.rT = QTextBrowser(self.centralwidget)
        self.rT.setObjectName(u"rT")
        self.rT.setGeometry(QRect(150, 144, 451, 31))
        self.cT = QLineEdit(self.centralwidget)
        self.cT.setObjectName(u"cT")
        self.cT.setGeometry(QRect(129, 16, 113, 21))
        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(30, 11, 121, 31))
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u9752\u5e74\u5927\u5b66\u4e60Check @AleryXiao", None))
        self.iB.setText(QCoreApplication.translate("MainWindow", u"\u9009\u62e9\u8f93\u5165\u6587\u4ef6\uff08\u53ef\u591a\u9009\uff09", None))
        self.oB.setText(QCoreApplication.translate("MainWindow", u"\u9009\u62e9\u8f93\u51fa\u6587\u4ef6", None))
        self.iT.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"hr { height: 1px; border-width: 0; }\n"
"li.unchecked::marker { content: \"\\2610\"; }\n"
"li.checked::marker { content: \"\\2612\"; }\n"
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u70b9\u51fb\u53f3\u4fa7\u6309\u94ae\u9009\u62e9Input\u6587\u4ef6\uff08\u540e\u53f0\u5bfc\u51fa\u7684\u8bb0\u5f55\uff09</p></body></html>", None))
        self.oT.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"hr { height: 1px; border-width: 0; }\n"
"li.unchecked::marker { content: \"\\2610\"; }\n"
"li.checked::marker { content: \"\\2612\"; }\n"
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u70b9\u51fb\u53f3\u4fa7\u6309\u94ae\u9009\u62e9Output\u6587\u4ef6\uff08\u540d\u5355\uff09</p></body></html>", None))
        self.rB.setText(QCoreApplication.translate("MainWindow", u"\u8fd0\u884c", None))
        self.rT.setHtml(QCoreApplication.translate("MainWindow", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"hr { height: 1px; border-width: 0; }\n"
"li.unchecked::marker { content: \"\\2610\"; }\n"
"li.checked::marker { content: \"\\2612\"; }\n"
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u6b64\u5904\u663e\u793a\u7a0b\u5e8f\u7684\u5f53\u524d\u72b6\u6001</p></body></html>", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u67e5\u8be2\u73ed\u7ea7\u7f16\u53f7:", None))
    # retranslateUi

猜你喜欢

转载自blog.csdn.net/aleryxiao/article/details/127972605