DEV Community

Steph Mojekwu
Steph Mojekwu

Posted on

load_workbook fails when loading excel file with blue style fill in cells. How do I fix the error? Click post to see error.

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'>

Enter fullscreen mode Exit fullscreen mode

How do I fix this error using python? Thank you!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay