Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl problem
#1
I got this problem while trying to study how to interpret an excel folder using Python. The error was saying that the sheet did not exist KeyError: 'Worksheet Sheet1 does not exist.', although I have checked several times that it does! I followed a Youtube tutorial and went through all necessary steps: I downloaded the required site-pack for excel (openpyxl) using the exact code pip install openpyxl, then typed the code needed to open it, YET it met an error! I did not make any mistakes while typing, as there weren't any warnings, so there must be something wrong with the system.
Here is the program:
 import openpyxl as xl
 wb = xl.load_workbook('transactions.xlsx')
 sheet = wb['Sheet1']
 cell = sheet['a1']
 print(cell)
And here is the error:
Error:
F:\expriment\venv\Scripts\python.exe F:/expriment/Experiment.py Traceback (most recent call last): File "F:/expriment/Experiment.py", line 3, in <module> sheet = wb['Sheet1'] File "F:\expriment\venv\lib\site-packages\openpyxl\workbook\workbook.py", line 273, in __getitem__ raise KeyError("Worksheet {0} does not exist.".format(key)) KeyError: 'Worksheet Sheet1 does not exist.'
Reply
#2
Please, don't post images of code. Copy/paste code in python tags, full traceback - in error tags.
See BBcode help for more info.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
The error is clear. The file does not have sheet named Sheet1. Check your file
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  openpyxl insert picture problem cools0607 2 1,396 May-03-2023, 06:48 AM
Last Post: cools0607
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 2,099 Sep-29-2020, 03:20 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020