由于 styles.xml 中的负相对缩进,无法使用 pandas 读取 XLSM 文件

Can't read XLSM file with pandas because of negative relativeIndents in styles.xml

使用 pandas 读取 XLSM 文件时出现以下错误:

  File "C:\Users\user\company\rollout\Skripte\\Puma.py", line 42, in run
    report_filter = pd.read_excel(bodopath + "Master ROO.xlsm", sheet_name='PUMA Auswertung', usecols="A:D")

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\util\_decorators.py", line 299, in wrapper
    return func(*args, **kwargs)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\io\excel\_base.py", line 336, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\io\excel\_base.py", line 1131, in __init__
    self._reader = self._engines[engine](self._io, storage_options=storage_options)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\io\excel\_openpyxl.py", line 475, in __init__
    super().__init__(filepath_or_buffer, storage_options=storage_options)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\io\excel\_base.py", line 391, in __init__
    self.book = self.load_workbook(self.handles.handle)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\pandas\io\excel\_openpyxl.py", line 486, in load_workbook
    return load_workbook(

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\reader\excel.py", line 317, in load_workbook
    reader.read()

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\reader\excel.py", line 281, in read
    apply_stylesheet(self.archive, self.wb)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\styles\stylesheet.py", line 198, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\styles\stylesheet.py", line 103, in from_tree
    return super(Stylesheet, cls).from_tree(node)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\descriptors\serialisable.py", line 83, in from_tree
    obj = desc.from_tree(el)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\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\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\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\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
    return cls(**attrib)

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\styles\alignment.py", line 52, in __init__
    self.relativeIndent = relativeIndent

  File "C:\Users\user\AppData\Local\WPy64-3940\python-3.9.4.amd64\lib\site-packages\openpyxl\descriptors\base.py", line 107, in __set__
    raise ValueError('Min value is {0}'.format(self.min))

ValueError: Min value is 0

谷歌搜索了一下后,问题似乎是 styles.xlm:

中的负缩进
    <dxf>
        <alignment relativeIndent="-1"/>
    </dxf>

我想知道是什么原因造成的,或者我是否可以在阅读 excel_file 之前解决这个问题。 例如,-1 relativeIndent 在 Workmap 中看起来如何?

此外,是的,我可以解决这个问题并重新上传 styles.xlm 但不知何故那些负缩进又出现了,有时甚至不止一个。

好的,我找到了解决方案。对于遇到同样问题的任何人:升级 openpyxl!

好的,我找到了解决方案。对于遇到同样问题的任何人:升级 openpyxl!