How to make my for loop work in openpyxl?

201 Views Asked by At

Hi I am in process of writing a python code to input search and edit data into excel.

my chosen format for the UI is PySimpleGUI and my xlsx package is openpyxl.

I have been coding for approximately 3 weeks.

I probably bit off more than I can chew but I won't give up.

I need to know why my for loop won't work so I can fix it.

here is the offending code:

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()

I have poored over the openpyxl docs for hours per night, and I have performed that many google searches I now have shares!!

0

There are 0 best solutions below