load_workbook fails when loading excel file with blue style fill in cells. How do I fix the error? Click post to see error.
Steph Mojekwu
Posted on May 16, 2023
I wrote a python script to load an excel file with blue style fill in the excel sheet (blue color background in cells) and the load_workbook function keeps failing with the error below:
wb = load_workbook(excel file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\reader\excel.py", line 299, in read
apply_stylesheet(self.archive, self.wb)
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\styles\stylesheet.py", line 198, in apply_stylesheet
stylesheet = Stylesheet.from_tree(node)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\styles\stylesheet.py", line 103, in from_tree
return super(Stylesheet, cls).from_tree(node)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
return cls(**attrib)
^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\styles\stylesheet.py", line 74, in __init__
self.fills = fills
^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\descriptors\sequence.py", line 27, in __set__
seq = self.container(_convert(self.expected_type, value) for value in seq)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\descriptors\sequence.py", line 27, in <genexpr>
seq = self.container(_convert(self.expected_type, value) for value in seq)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\<username>\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\descriptors\base.py", line 61, in _convert
raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'openpyxl.styles.fills.Fill'>
How do I fix this error using python? Thank you!
💖 💪 🙅 🚩
Steph Mojekwu
Posted on May 16, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.