简体   繁体   English

无法使用openpyxl加载工作簿:在处理上述异常期间,发生了另一个异常

[英]Can't load workbook with openpyxl: during handling of the above exception, another exception occurred

I want to edit a xlsx file with openpyxl 2.5.0. 我想用openpyxl 2.5.0编辑xlsx文件。

This is my code and it works with an empty file: 这是我的代码,它适用于空文件:

from openpyxl import load_workbook

wb = load_workbook(filename="Untitled.xlsx")
ws = wb.active
ws["B5"] = "test"
wb.save("Export.xlsx")

However if I try to load this file , I get the following obscure error. 但是,如果我尝试加载此文件 ,我会收到以下模糊错误。

Traceback (most recent call last):
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\base.py", line 57, in _convert
    value = expected_type(value)
ValueError: invalid literal for int() with base 10: 'l'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Matteo\PyCharm\CMakeR\XLSXEditor.py", line 3, in <module>
    wb = load_workbook(filename="Modulo CMR.xlsx")
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\reader\excel.py", line 274, in load_workbook
    for c in find_charts(archive, rel.target):
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\chart\reader.py", line 43, in find_charts
    drawing = SpreadsheetDrawing.from_tree(tree)
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 84, in from_tree
    obj = desc.expected_type.from_tree(el)
  [Previous line repeated 1 more times]
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 100, in from_tree
    return cls(**attrib)
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\drawing\shapes.py", line 349, in __init__
    self.l = l
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\base.py", line 69, in __set__
    value = _convert(self.expected_type, value)
  File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\base.py", line 59, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected <class 'int'>

I have really no clue what might be causing it. 我真的不知道可能导致它的原因。 But from searching the internet, I gathered that it might be related to a style/formatting conversion issue. 但是从搜索互联网,我收集到它可能与样式/格式转换问题有关。

Thanks to Charlie Clark I noticed that - if I downgrade openpyxl to 2.4.9 - I can work around this issue. 感谢Charlie Clark,我注意到 - 如果我将openpyxl降级到2.4.9 - 我可以解决这个问题。 So it seems to be some sort of bug related to 2.5.0. 所以它似乎是与2.5.0相关的某种错误。

Today it looks like there are only two solutions: 今天看起来只有两种解决方案:

  1. Remove graphics from Excel workbook. 从Excel工作簿中删除图形。
  2. Downgrade to openpyxl version < 2.5.0. 降级到openpyxl版本<2.5.0。

Refer to https://bitbucket.org/openpyxl/openpyxl/issues/967/expected-type-error-since-250 请参阅https://bitbucket.org/openpyxl/openpyxl/issues/967/expected-type-error-since-250

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在处理上述异常的过程中,又发生了一个异常 - During handling of the above exception, another exception occurred 在处理上述异常期间,发生了另一个异常:Python程序 - During handling of the above exception, another exception occurred: Python program KeyError: 1 在处理上述异常的过程中,又发生了一个异常: - KeyError: 1 During handling of the above exception, another exception occurred: 在处理上述异常的过程中,又发生了一个异常:&amp; google sheet not found - During handling of the above exception, another exception occurred: & google sheets not found “在处理上述异常过程中,发生了另一个异常”for循环中的第一个输入 - “ during the handling of above exception, another exception occurred ” for the first input in the for loop 如何解决“在处理上述异常期间,发生了另一个异常:” - How to fix "During handling of the above exception, another exception occurred: " Flask-restful - 在处理上述异常的过程中,发生了另一个异常 - Flask-restful - During handling of the above exception, another exception occurred 关键错误:1 在处理上述异常的过程中,发生了另一个异常 - Key Error: 1 During handling of the above exception, another exception occurred KeyError:在处理上述异常的过程中,发生了另一个异常 - KeyError: During handling of the above exception, another exception occurred 在处理上述异常的过程中,发生了另一个异常:'Date' - During handling of the above exception, another exception occurred: 'Date'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM