3

I was trying out Openpyxl, and wrote the following code:

from openpyxl import load_workbook, __version__ workbook = load_workbook(filename="Contacts.xlsx") sheet = workbook.active 

That's it, no other code.

I got the following error on running: (TL;DR, due to line 2, I got "TypeError: __init__() got an unexpected keyword argument 'extLst'")

"C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\Scripts\python.exe" "C:/Users/taijee/Documents/PythonAll/Python Scripts/newfile.py" Traceback (most recent call last): File "C:/Users/taijee/Documents/PythonAll/Python Scripts/newfile.py", line 2, in <module> workbook = load_workbook(filename="Contacts.xlsx") File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\reader\excel.py", line 315, in load_workbook reader.read() File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\reader\excel.py", line 279, in read apply_stylesheet(self.archive, self.wb) File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 192, in apply_stylesheet stylesheet = Stylesheet.from_tree(node) File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 102, in from_tree return super(Stylesheet, cls).from_tree(node) File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 83, in from_tree obj = desc.from_tree(el) File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\descriptors\sequence.py", line 85, in from_tree return [self.expected_type.from_tree(el) for el in node] File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\descriptors\sequence.py", line 85, in <listcomp> return [self.expected_type.from_tree(el) for el in node] File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\styles\fills.py", line 64, in from_tree return PatternFill._from_tree(child) File "C:\Users\taijee\Documents\PythonAll\Python Scripts\venv\lib\site-packages\openpyxl\styles\fills.py", line 102, in _from_tree return cls(**attrib) TypeError: __init__() got an unexpected keyword argument 'extLst' Process finished with exit code 1 

I've searched for similar problems and found one, but it was from 2014 so the solution given was to download version 2.0 of Openpyxl instead of 2.2. The openpyxl version is 3.0.4, python version 3.8.3, and Contacts.xlsx definitely exists in the same folder.

Edit:

Making a new file had worked, but I recently made another program using openpyxl. It was working fine but it suddenly broke, giving an error very similar to the one above (I didn't record it at the time, but the last line TypeError: __init__() got an unexpected keyword argument 'extLst' definitely matched).

I had made no changes to the program between the successful runs and the unsuccessful ones, so I concluded the file was at fault. I had opened and closed the file once, though I don't remember whether the very next run was the one when it broke. After the error appeared, when I opened the file I couldn't save any changes - it gave some sort of error.

Note: I don't have Office, so I'm using Planmaker of the SoftMaker Office Suite to open the .xlsx files when I need to.

I deleted the file and created a new one with the same name so as to not change the code, but the problems persisted with the new file, including the inability to save changes.

Only when I created a new file with a different name did the code work.

It may not even be an openpyxl problem, but rather a Planmaker problem, though I don't understand why the error would be the one I keep getting.

Neverthless, If someone could explain why this happens or how to fix it, I'll be really grateful. Meanwhile, I'll see if a file I never use openpyxl on will still give me the same problem, and if it does, whether openpyxl gives the same error with that file when used in a program.

4
  • There's something wrong with your file because pattern fills don't have any extensions. Commented Jul 6, 2020 at 17:58
  • Can you tell us about the directory where your file lives? Typically these kinds of errors come from a mismatch between where the file sits and where you're pointing. You can check which directory python is looking at with import os print(os.getcwd()) Commented Jul 6, 2020 at 22:46
  • Ok, @jmb, I'll check that. Commented Jul 7, 2020 at 6:00
  • @Charlie Clark, I'll make a new file and try it out. Commented Jul 7, 2020 at 6:00

5 Answers 5

4

I too was using Planmaker of the SoftMaker Office Suite, got the same error when I try to edit one of my .xlsx with openpyxl. The only solution that I found is by not using the Planmaker and go back to MS Excel.

As much as I don't like MS Excel like the next guy, but it works flawlessly with openpyxl.

Probably not the solution you seek, but it's a solution for me at least.

Sign up to request clarification or add additional context in comments.

Comments

2

Just a note, in case others stumble over this: openpyxl in the latest version (3.0.10) seems to now raise an error on the "unexpected keyword". Before you could using the warnings-module to ignore it. No more. Since I am working on Linux, going to MS Excel is not an option, so I rewrote my latest Python project to use pylightxl instead of openpyxl. It more hassle, as it has a lot less functionality, but it does not choke on Softwaker's extensions. – Hendrik

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
2

I got the same error TypeError: __init__() got an unexpected keyword argument 'extLst' because I changed and saved a tabular workbook file in xlsx format with Planmaker software.

Thereafter I saved this file with libreoffice calc. Then loading of this xlsx file with openpyxl was working.

This might be a workaround for some users.

Comments

0

I also got this error from using planmaker. I resaved the file using *.xls in planmaker and was able to load the file in python again. I know its not the ideal format but works until i can get to work.

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Resaving as xlsx file did not work on my MAC :-(
resave as xls not xlsx.
0

Unfortunately, the problem is the way that Planmaker saves the file. I found a very simple solution:

Open your file in Google Sheets then save it again, will work instantly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.