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!

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs