KeyError: 'Worksheet a8 does not exist.'

Hello folk

I am new to python, like very new, and this error has me scratching my head. The excel file and work sheets do exist. If I go into idle I can interact with them. I have been running the program without this error and while tweaking code further down this problem raised it’s head. The error pops up about half way down the program at an ’If’ statement, which has been doing a good job until today. Can anyone point me in the right direction as to solve where I went off track. Any help will be most appreciated. Many thanks in advance and enjoy your weekend.

Bob

Can you try using a capital letter? Say A8 instead of lower case a8 when referencing the cell.
If that doesn’t work, you’ll have to provide your script for review.

  • One other small point, maybe it was a typo, but if should be lower case:

Hi Paul, Thanks for the reply. I have checked and the “if” statement is in lower case. I have also done a search for ”a8” and there is no reference to it anywhere in the script. I am happy to send the script and Excel file. Do I post it on here?

Once again thank you

Stuart Brown

Did you try capital letter? As in A8?

You can post your script here for review. Make sure that it is properly formatted so that it appears precisely as it does on your terminal. You can do this by pasting your script here, selecting ALL of it (make sure all of it is highlighted), then clicking the “</>” tool above (when in edit mode). This way your script appears like this, for example:

def some_function_here(x, y, z): 
    
    sum_of_three = x + y + z

    print(f'The sum of {x}, {y}, and {z} is: {x+y+z}.')

Hi Paul

Thanks for the assist but it is sorted out.

I am not sure what was wrong but I fixed it. Or should I say it is fixed?

Thanks again

Good day Paul

I hope I am doing this correctly. If not, let me know and I will try again.

Basically I want to display, on the screen, a list a list of data defined by the columns I have chosen. I would like to have the rows highlighted for easy of reading.

If you run the script as I have sent you will notice that the data is displayed correctly but without the highlighting the rows. You will also notice that the last few rows

contain the headings, one after the other and beautifully highlighted, which is quite sad really as this is not meant to happen..

If you ignore from line 56 to 70 you will notice that it displays the data correctly without adding the heading at the bottom but still no highlighting.

I have been scratching my head for way too long and am reaching out you for some guidance, if not a solution.

I have also attached the .xlsx and .py files.

All the print statements are to help me keep track of where I have been and done. Fat lot of help that has been.

import pandas as pd

import tkinter as tk

from tkinter import ttk

from openpyxl import load_workbook

from openpyxl.styles import Border, Side

from datetime import datetime

root1 = tk.Tk()

root1.geometry(‘590x900’)

root1.title(‘Jobs for Router department.’)

#Add Style

style = ttk.Style()

##Pick a themestyle.theme_use(‘default’)

1. Load the relevant colomns from the Excel file

path = “C:\Users\Stuart\Documents\Python stuff\info.xlsx”

wb = load_workbook(‘info.xlsx’)

ws = wb[‘Sheet1’]

df = pd.read_excel(‘info.xlsx’, usecols=[0, 1, 2, 3, 8, 15])

df = df.fillna(‘’)

df = df[1:]

print(‘Step 1’)

print(df)

setup treeview

columns = (‘Doc No’, ‘Order Number’, ‘Customer’, ‘Date’, ‘Router’, ‘Complete’)

tree = ttk.Treeview(root1, columns = columns, show = ‘headings’, height = 80)

#tree = ttk.Treeview(root1, columns = columns, height = 80)

#tree = ttk.Treeview(root1, show = “headings”, height = 20)

#tree = ttk.Treeview(root1, show=“headings”)

c = 0

print(‘Step 2’)

for col in df.columns:

tree.heading(col, text=col)

tree.column(col, width=100)

c +=1

print('Col ’ + str(c))

d = 0

for index, row in df.iterrows():

tree.insert(“”, “end”, values=list(row))

d += 1

#tree.pack(expand=True, fill=‘both’)

#tree.pack()

print(‘Step 3’)

print('Row ’ + str(d))

Set up striped effect, Light blue for even numbers and white for odd numbers

global row_count

row_count = 0

tree.tag_configure(‘oddrow’, background = ‘white’)

tree.tag_configure(‘evenrow’, background = ‘lightblue’)

print(df)

(Attachment send-away.py is missing)

(Attachment info.xlsx is missing)

Hi Stuart,

please read my previous post and format your script so that it appears here as it does on your screen. This improves readability on our side and helps you verify that you have entered it correctly.

There are multiple sections so each section needs to be properly formatted in its own right.