Python Forum
openpyxl problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: openpyxl problem (/thread-24993.html)



openpyxl problem - Sheeper - Mar-14-2020

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.'



RE: openpyxl problem - buran - Mar-14-2020

Please, don't post images of code. Copy/paste code in python tags, full traceback - in error tags.
See BBcode help for more info.


RE: openpyxl problem - buran - Mar-14-2020

The error is clear. The file does not have sheet named Sheet1. Check your file