Error with opening/reading xlsx file in Python openpyxl

Viewed 47

At my work we have a piece of equipment that spits out a bunch xlsx files. I want to open all of them and copy a few cells and put them together into a new xlsx file.

The main problem is that I can not even open one file.

from pathlib import Path
import openpyxl
path = Path(".")
filesxlsx = path.glob('*.xlsx')
importeddataxlsx = [openpyxl.load_workbook(filename) for filename in filesxlsx]

It gives the following error at the line with openpyxl.load_workbook(filename):

Traceback (most recent call last):
  File "C:\path.py", line 55, in _convert
    value = expected_type(value)
TypeError: Fill() takes no arguments

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\path.py", line 113, in <module>
    a.importdata3()
  File "C:\path.py", line 102, in importdata3
    wb = openpyxl.load_workbook(path, read_only=True, data_only=True)
  File "C:\path.py", line 317, in load_workbook
    reader.read()
  File "C:\path.py", line 281, in read
    apply_stylesheet(self.archive, self.wb)
  File "C:\path.py", line 198, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
  File "C:\path.py", line 103, in from_tree
    return super(Stylesheet, cls).from_tree(node)
  File "C:\path.py", line 103, in from_tree
    return cls(**attrib)
  File "C:\path.py", line 74, in __init__
    self.fills = fills
  File "C:\path.py", line 26, in __set__
    seq = [_convert(self.expected_type, value) for value in seq]
  File "C:\path.py", line 26, in <listcomp>
    seq = [_convert(self.expected_type, value) for value in seq]
  File "C:\path.py", line 57, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'openpyxl.styles.fills.Fill'>

However, if I open the files and press ctrl+s and close it again. Then it does work, there is no error and openpyxl can open and read the files.

Does anyone know a better solution to this issue, so that openpyxl can just open the files without fault and without having to manually open and save each file?

0 Answers
Related