Python Forum
Openpyxl error message. Help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl error message. Help!
#1
Hi. I am following some text book lessons. I am trying to convert Column Letters to Numbers and getting the following error message.
>>> import openpyxl
>>> from openpyxl.cell import get_column_letter, column_index_from_string
Traceback (most recent call last):
  File "<pyshell#82>", line 1, in <module>
    from openpyxl.cell import get_column_letter, column_index_from_string
ImportError: cannot import name 'get_column_letter' from 'openpyxl.cell' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/cell/__init__.py)
Reply
#2
https://openpyxl.readthedocs.io/en/stabl...a-workbook

the import is from openpyxl.utils, not openpyxl.cell
from openpyxl.utils import get_column_letter, column_index_from_string
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
thank you. that has worked. I am trying to follow an exercises from a book called Automate The Boring Stuff and although i am following the code accurately it is coming up with errors such as the above. For example yesterday i typed;
>>> 'Row ' +str(c.row)+', Column ' + c.column + ' is ' + c.value
Traceback (most recent call last):
  File "<pyshell#67>", line 1, in <module>
    'Row ' +str(c.row)+', Column ' + c.column + ' is ' + c.value
TypeError: can only concatenate str (not "int") to str
which was exactly as the book stated,when it should have been;
>>> 'Row ' + str(c.row) + ',Column ' + str(c.column) + ' is ' + c.value
'Row 1,Column 2 is Apples'

i received the correction here on this forum.
is it possible there has been many updates to python since the book was written?
Reply
#4
there are updates/changes for sure, but this particular case should be in book's errata. As you can see they have converted the c.row, but not c.column - clear mistake on their part.
This is also good example while string formatting is preferred compared to concatenation

Note that if c.value was a number (not str - 'Apple') - you should have converted it too
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
#5
so the openpyxl.cell and not utlis as it should is another misprint?
Reply
#6
(Sep-24-2019, 07:20 PM)Shafla Wrote: so the openpyxl.cell and not utlis as it should is another misprint?
I cannot be so sure in this case. openpyxl is third party package and there may have been changes in their api. If you are curious you may check the changelog.

YEP, there was change in the openpyxl API - https://openpyxl.readthedocs.io/en/stabl...2015-02-18
Quote:Moved ancillary functions and classes into utils package - single place of reference
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
#7
thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error message about iid from RandomizedSearchCV Visiting 2 932 Aug-17-2023, 07:53 PM
Last Post: Visiting
  Another Error message. the_jl_zone 2 942 Mar-06-2023, 10:23 PM
Last Post: the_jl_zone
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,671 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  understanding error message krlosbatist 1 1,854 Oct-24-2021, 08:34 PM
Last Post: Gribouillis
  Installed pip install openpyxl, Requirement already satisfied, but, still have error jonah88888 3 6,512 Sep-24-2021, 02:11 AM
Last Post: jonah88888
  Error message pybits 1 35,871 May-29-2021, 10:26 AM
Last Post: snippsat
  f-string error message not understood Skaperen 4 3,267 Mar-16-2021, 07:59 PM
Last Post: Skaperen
  Overwhelmed with error message using pandas drop() EmmaRaponi 1 2,300 Feb-18-2021, 07:31 PM
Last Post: buran
  Winning/Losing Message Error in Text based Game kdr87 2 2,926 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  Don't understand error message Milfredo 2 1,994 Aug-24-2020, 05:00 PM
Last Post: Milfredo

Forum Jump:

User Panel Messages

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