I cannot load my excel file though openpyxl

Issue #1182 resolved
박형렬 created an issue

there. I cannot load my excel file though openpyxl. the file is 1,402KB. I tried to do New excel file. it can be opened. but my excel file show below error.

D:\1.업무\Python\venv\Scripts\python.exe D:/1.업무/Python/AVDD.py
Traceback (most recent call last):
  File "D:/1.업무/Python/AVDD.py", line 5, in <module>
    wb = load_workbook(filename)
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\reader\excel.py", line 312, in load_workbook
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\reader\excel.py", line 273, in read
    apply_stylesheet(self.archive, self.wb)
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 189, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 103, in from_tree
    return super(Stylesheet, cls).from_tree(node)
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 104, in from_tree
    return cls(**attrib)
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 93, in __init__
  File "D:\1.업무\Python\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 166, in _normalise_numbers
    fmt = BUILTIN_FORMATS[style.numFmtId]
KeyError: 56

this is my code

from openpyxl import load_workbook
from openpyxl.drawing.image import Image

wb = load_workbook(filename)

Comments (7)

  1. CharlieC

    Thanks, your local is ko-kr, right? The quickest solution is going to be to return either the General number format or the ISO date format (this range seems to be reserved for dates). What do you think?

  2. 박형렬 reporter

    yes, my local is ko-kr. I am sorry. I am not good at English and python. do you mean that i have to change format of my excel file?

  3. CharlieC

    The best thing is to specify the format manually. Internally Excel uses some builtin formats. Some of these are known to openpyxl, but others such as the one you have are locale specific. So, in Korean format number 56 is yyyy-mm-dd but on a Japanese computer this would be m"月"d"日".

    If you manually set the format to yyyy-mm-dd as opposed to selecting a standard format then Excel will save the format explicitly and openpyxl will be able to read it.

    I will look at improving the support for these formats in the near future but that is the quickest solution for you at the moment.

    I hope this isn't too complicated for you.

  4. CharlieC

    Ignore locale specific format as unknowable at runtime. Should probably default to a date format as the documented formats are all dates, though the cells tend to store the values as text. Resolves #1182

    → <<cset 8a7a177d3b90>>

  5. CharlieC

    You will need to use a checkout for this to work. It only seems to affect a few cells (F62:F65) in the sheet called Report. Excel stores actually seems to store these as both text values (using the formatting you see) and numbers. openpyxl handles the values as cells and ignores the formatting. This should allow you to work with the file.

  6. Log in to comment