0

嗨,我正在编写一个 python 代码来将搜索和编辑数据输入到 excel 中。

我为 UI 选择的格式是 PySimpleGUI,我的 xlsx 包是 openpyxl。

我已经编码了大约 3 周。

我可能咬得比我能咀嚼的多,但我不会放弃。

我需要知道为什么我的 for 循环不起作用,以便我可以修复它。

这是有问题的代码:

import PySimpleGUI as sg
import pandas as pd
import openpyxl as op

def weekly_wage():

    filename = 'Payroll.xlsx'

    wb = op.load_workbook(filename, data_only=True)

    ws = wb.worksheets[0]

    ws_tables = []


    layout = [
        [sg.Text('Employee Name', size=(15,1), font=('ariel', 16)), sg.InputText(key='-Name-', font=('ariel',16))],
        [sg.Text('Week Ending', size=(15,1), font=('ariel',16)), sg.InputText(key='-Date-', font=('ariel',16))],
        [sg.Submit(font=('ariel', 16))],
        [sg.Text('The Weekly Wage is:', font=('ariel', 16))],
        [sg.Output(size=(10, 1))]
    ]

    window = sg.Window('Gross Wages Search', layout, size=(450,250))

    # Event Loop
            
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED:
            break
        if event == 'Submit':
        if event == 'Submit':
            key1 = window['-Name-']      # this gives a callable object to the Input keys
            key2 = window['-Date-']
            rows = ws.iter_rows()

            name = []
            date = []
            gross = []
                                   
            for a,b,aw in rows:
                    name.append(a)
                    date.append(b)
                    gross.append(aw)
                    if a.value == key1 and b.value == key2:
                        print (aw.value)
                        break
                    else:
                        print('Try Again')
                        break


    window.close()

weekly_wage()

我每晚花了好几个小时阅读 openpyxl 文档,并且执行了许多我现在分享的谷歌搜索!

4

0 回答 0