Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

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:Usersaj200DocumentsGitHubMy-ProjectsMy-ProjectsActive ProjectsAutomated Corona VirusStart.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:Python39libsite-packagesopenpyxl
eaderexcel.py", line 315, in load_workbook
    reader.read()
  File "C:Python39libsite-packagesopenpyxl
eaderexcel.py", line 280, in read
    self.read_worksheets()
  File "C:Python39libsite-packagesopenpyxl
eaderexcel.py", line 255, in read_worksheets
    charts, images = find_images(self.archive, rel.target)
  File "C:Python39libsite-packagesopenpyxl
eaderdrawings.py", line 39, in find_images
    cs = get_rel(archive, deps, rel.id, ChartSpace)
  File "C:Python39libsite-packagesopenpyxlpackaging
elationship.py", line 168, in get_rel
    obj = cls.from_tree(tree)
  File "C:Python39libsite-packagesopenpyxldescriptorsserialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:Python39libsite-packagesopenpyxldescriptorsserialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:Python39libsite-packagesopenpyxlchartplotarea.py", line 140, in from_tree
    self = super(PlotArea, cls).from_tree(node)
  File "C:Python39libsite-packagesopenpyxldescriptorsserialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:Python39libsite-packagesopenpyxldescriptorsserialisable.py", line 103, in from_tree
    return cls(**attrib)
  File "C:Python39libsite-packagesopenpyxlchartar_chart.py", line 98, in __init__
    super(BarChart, self).__init__(**kw)
  File "C:Python39libsite-packagesopenpyxlchartar_chart.py", line 57, in __init__
    self.grouping = grouping
  File "C:Python39libsite-packagesopenpyxldescriptors
ested.py", line 35, in __set__
    super(Nested, self).__set__(instance, value)
  File "C:Python39libsite-packagesopenpyxldescriptorsase.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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...