Search code examples
pythonpython-3.xexcelruntime-erroropenpyxl

Python openpyxl library refusing to load my excel document


I have worked with excel documents in the past, but for some reason python is REFUSING to open this particular one. I haven't had issues with the openpyxl library before.

The error I'm recieving is this:

Traceback (most recent call last):
  File "C:\Users\aj200\Documents\GitHub\My-Projects\My-Projects\Active Projects\Automated Corona Virus\Start.py", line 160, in <module>
    book = openpyxl.load_workbook('C:/Users/aj200/Documents/GitHub/My-Projects/My-Projects/Active Projects/Automated Corona Virus/Active-Coronavirus-cases.xlsx')
  File "C:\Python39\lib\site-packages\openpyxl\reader\excel.py", line 315, in load_workbook
    reader.read()
  File "C:\Python39\lib\site-packages\openpyxl\reader\excel.py", line 280, in read
    self.read_worksheets()
  File "C:\Python39\lib\site-packages\openpyxl\reader\excel.py", line 255, in read_worksheets
    charts, images = find_images(self.archive, rel.target)
  File "C:\Python39\lib\site-packages\openpyxl\reader\drawings.py", line 39, in find_images
    cs = get_rel(archive, deps, rel.id, ChartSpace)
  File "C:\Python39\lib\site-packages\openpyxl\packaging\relationship.py", line 168, in get_rel
    obj = cls.from_tree(tree)
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Python39\lib\site-packages\openpyxl\chart\plotarea.py", line 140, in from_tree
    self = super(PlotArea, cls).from_tree(node)
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
    return cls(**attrib)
  File "C:\Python39\lib\site-packages\openpyxl\chart\bar_chart.py", line 98, in __init__
    super(BarChart, self).__init__(**kw)
  File "C:\Python39\lib\site-packages\openpyxl\chart\bar_chart.py", line 57, in __init__
    self.grouping = grouping
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\nested.py", line 35, in __set__
    super(Nested, self).__set__(instance, value)
  File "C:\Python39\lib\site-packages\openpyxl\descriptors\base.py", line 128, in __set__
    raise ValueError(self.__doc__)
ValueError: Value must be one of {'standard', 'clustered', 'stacked', 'percentStacked'}

Unfortunately, google seems to be of no help with this particular one, and I don't know what the problem is or where it has occured. I presume it's a weirdly formatted cell or something?

The code to replicate this is as follows:

import openpyxl

book = openpyxl.load_workbook('C:/Users/aj200/Documents/GitHub/My-Projects/My-Projects/Active Projects/Automated Corona Virus/Active-Coronavirus-cases.xlsx')

And the download link to the excel file in question. Unfortunately I could not just upload it here directly as I would have preferred: https://www.mediafire.com/file/nra5ekm2n8l0yd2/Active-Coronavirus-cases.xlsx/file

It seems to open perfectly fine through excel, but for some reason my code is erroring out upon attempting to load it.

If anyone could give me a pointer as to what the issue could be, I would be immensely greatful! Normally google would give me an answer, or at least a pointer to the problem, but alas this time it has not helped.

Thanking you all in advance, Andrey

P.S. I've deleted all data in every cell of both worksheets, and the error still persists. So it is definitely a formatting issue of some sort


Solution

  • There is some problem with the spreadsheet itself, it's only opening in a read-only mode and when I click enable editing it's asking me to repair it.

    Repair the spreadsheet

    After repair completion, it removed some drawings in itRepair status

    After that the python code is able to read it without any errors.

    Repaired excel is here https://www.mediafire.com/file/wr8jqka9e90g6wa/Active-Coronavirus-cases.xlsx/file