openpyxl KeyError Worksheet {0} does not exist openpyxl KeyError Worksheet {0} does not exist tkinter tkinter

openpyxl KeyError Worksheet {0} does not exist


from openpyxl import load_workbookwb = load_workbook('file.xlsx')print(wb.sheetnames)for worksheets in wb.sheetnames:worksheet = wb[worksheets]print(worksheet)

You need to iterate through the NAMES of the worksheets (wb.sheetnames), rather than through the indices of the worksheets (wb)


def get_1():    global sheet1    sheet1 = e1.get("1.0", "end-1c")    print(sheet1)def get_2():    global sheet2    sheet2 = e2.get("1.0", "end-1c")    print(sheet2)

When you call the following lines

sheet1 = e1.get("1.0", "end-1c")sheet2 = e2.get("1.0", "end-1c")

at that time, there is nothing in e1 and e2.So u have to call it in a function like for the filenames.

Moreover, you should use Entry widget for getting inputs