简体   繁体   中英

Opening xlsx file with Openpyxl gives KeyError '$A$' - Python

I am trying to open an Excel file (xlsx) using openpyxl:

data = pd.read_excel('C:/Users/jsm_24_02/item-report (1).xlsx', engine = 'openpyxl')

However I keep getting this error:

...
C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\worksheet\_reader.py in parse_cell(self, element)
   188 
   189         if coordinate:
--> 190             row, column = coordinate_to_tuple(coordinate)
   191             self.col_counter = column
   192         else:

C:\ProgramData\Anaconda3\lib\site-packages\openpyxl\utils\cell.py in coordinate_to_tuple(coordinate)
   200     col = coordinate[:idx].upper()
   201     row = coordinate[idx:]
--> 202     return int(row), _COL_STRING_CACHE[col]
   203 
   204 

KeyError: '$A$'

Google does not show any similar errors since both the dollar signs ($) do not show up searches when typing:

$A$

I tried renaming the file as well as using openpyxl.load_workbook but the only thing that worked was opening the file, enabling editing and closing the file. That is not an option since it's part of a scheduled job.

Thank!

Sadly, it looks like this is an issue with the openpyxl library , which was reported to the repository over a year ago.

Probably the most you can do is add a comment to the issue saying you're affected by it too so that the maintainers are encouraged to fix it up, or otherwise create a merge request and fix it yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM