日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

mport sys
import os
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon
import xlrd
import datetime
import time
from openpyxl import Workbook
from openpyxl.styles import Border, Side, PatternFill, Font, GradientFill, Alignment

class MainGUI(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()        
        self.setWindowTitle("領(lǐng)料明細(xì)匯總")
        self.resize(800, 400)
        self.main_widget = QtWidgets.QWidget()        
        self.main_widget_layout = QtWidgets.QGridLayout()
        self.main_widget.setLayout(self.main_widget_layout)

        self.input = QtWidgets.QLineEdit()
        self.input_btn = QtWidgets.QPushButton("選擇輸入文件夾")
        self.output = QtWidgets.QLineEdit()
        self.output_btn = QtWidgets.QPushButton("選擇輸出文件夾")
        self.show_result = QtWidgets.QListWidget()
        self.run = QtWidgets.QPushButton("執(zhí)行匯總")

        self.main_widget_layout.addWidget(self.input,0,0,1,2)
        self.main_widget_layout.addWidget(self.input_btn, 0, 2, 1, 1)
        self.main_widget_layout.addWidget(self.output,1,0,1,2)
        self.main_widget_layout.addWidget(self.output_btn, 1, 2, 1, 1)
        self.main_widget_layout.addWidget(self.run, 2, 2, 1, 1)
        self.main_widget_layout.addWidget(self.show_result, 3, 0, 3, 3)

        self.setCentralWidget(self.main_widget)
        
        self.input_btn.clicked.connect(self.Choice_dir_input) #將"選擇輸入文件夾"按鈕綁定Choice_dir_input函數(shù)
        self.output_btn.clicked.connect(self.Choice_dir_output) #將"選擇輸出文件夾"按鈕綁定Choice_dir_output函數(shù)
        self.run.clicked.connect(self.Summary_data) #“執(zhí)行匯總”按鈕綁定Summary_data函數(shù)

    def Choice_dir_input(self):
        #選擇目錄操作
        dir_path = QtWidgets.QFileDialog.getExistingDirectory(self, "請選擇文件夾路徑", "D:\")
        #將選擇的目錄顯示在文本編輯框中
        self.input.setText(dir_path)
        
    def Choice_dir_output(self):
        dir_path = QtWidgets.QFileDialog.getExistingDirectory(self, "請選擇文件夾路徑", "D:\")
        self.output.setText(dir_path)
        
    def Get_data(self, file):
        '''獲取單個Excel文件中的資料'''
        wb = xlrd.open_workbook(file)
        ws = wb.sheets()[0]
        data = {}
        for row in range(7, ws.nrows-2):
            card_id = ws.cell(2, 16).value
            car = ws.cell(3, 16).value
            dt = ws.cell(row, 0).value
            if type(dt) is float:
                date_time = xlrd.xldate.xldate_as_datetime(dt, 0)
            else:
                date_time = datetime.datetime.strptime(dt,'%Y-%m-%d %H:%M:%S')
            business = ws.cell(row, 2).value
            model = ws.cell(row, 3).value
            qty = ws.cell(row, 4).value
            unit_price = ws.cell(row, 6).value
            price = ws.cell(row, 8).value
            reward = ws.cell(row, 9).value
            discount = ws.cell(row, 11).value
            balance = ws.cell(row, 13).value
            location = str(ws.cell(row, 15).value).strip()
            operator = ws.cell(row, 17).value
            date = date_time.date()
            time = date_time.time()
            info_list=[card_id,car,date_time,business,model,qty,unit_price,price,reward,discount,
                       balance,location,operator,date,time]
            data.setdefault(date,[])
            if info_list[3] != "備注":
                data[date].Append(info_list)
        #增加當(dāng)日加油次數(shù)        
        for key in data.keys():
            for i in data[key]:
                i.append(len(data[key]))
        return data
    
    def Get_file_path(self,path):        
        files=[]
        for file in os.listdir(path):
            if file.endswith(".xls"): #排除文件夾內(nèi)的其它干擾文件
                files.append(path+"\"+file)
        return files
    
    def Get_current_time(self):
        time_stamp = time.time()  # 當(dāng)前時間的時間戳
        local_time = time.localtime(time_stamp)  #
        str_time = time.strftime('%Y-%m-%d %H.%M.%S', local_time)
        return str_time
    
    def Summary_data(self,files):
        thin = Side(border_style="thin", color="000000")#定義邊框粗細(xì)及顏色
        title = ['部門', '部門編號', '時間', '業(yè)務(wù)類型', '品種', '數(shù)量', '單價', '金額', '額外值',
         '調(diào)整', '剩余', '庫位', '操作員', '領(lǐng)取日期', '領(lǐng)取時間', '領(lǐng)取次數(shù)']

        wb = Workbook() 
        ws = wb.active
        ws.merge_cells("A1:P1")
        ws.cell(1,1).value = "領(lǐng)料明細(xì)匯總表"
        ws.cell(1,1).font = Font(name=u'黑體',bold=True,size=18)
        ws.row_dimensions[1].height  = 22.2
        ws.cell(1,1).alignment = Alignment(horizontal="center", vertical="center")
        ws.append(title)

        #插入數(shù)據(jù)
        files = self.Get_file_path(self.input.text()) #獲取文本編輯框中的輸入文件目錄,并獲取目錄下的xls文件
        for file in files:
            data = self.Get_data(file)
            for key in data.keys():
                for i in data[key]:
                    ws.append(i)
            f = QtWidgets.QListWidgetItem(f"{file} 的內(nèi)容已加入總表.") # 創(chuàng)建一個顯示項
            self.show_result.addItem(f) # 將結(jié)果添加到部件中

        #設(shè)置字號,對齊,縮小字體填充,加邊框
        #Font(bold=True)可加粗字體
        for row_number in range(2, ws.max_row+1):
            for col_number in range(1,17):
                c = ws.cell(row=row_number,column=col_number)
                c.font = Font(size=9)
                c.border = Border(top=thin, left=thin, right=thin, bottom=thin)
                c.alignment = Alignment(horizontal="left", vertical="center")

        col_name= list("ABCDEFGHIJKLMNOP")
        col_width = [8, 8, 16, 8, 16, 8, 8, 9.8, 8, 8, 8, 11, 8.3, 9, 8, 8]
        for i in range(len(col_name)):
            ws.column_dimensions[col_name[i]].width = col_width[i]

        ws.column_dimensions.group('I','K',hidden=True)
        ws.column_dimensions.group('N','O',hidden=True)

        wb.save(f"{self.output.text()}\領(lǐng)料明細(xì)匯總表{self.Get_current_time()}.xlsx")
        f = QtWidgets.QListWidgetItem(f"n領(lǐng)料明細(xì)匯總表{self.Get_current_time()}.xlsx 已生成,請去輸出文件夾查看.") # 創(chuàng)建一個顯示項
        self.show_result.addItem(f) # 將結(jié)果添加到部件中

            
def main():
    app = QtWidgets.QApplication(sys.argv)
    app.setWindowIcon(QIcon("PO.ico"))#設(shè)置界面左上角圖標(biāo)
    gui = MainGUI()
    gui.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

 

 

分享到:
標(biāo)簽:Python
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達(dá)人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定