今天帮同学写个分类统计报表数据并写入excel的小脚本,在我的电脑上运行正常,帮他装了python,安装了2.5.5版本的openpyxl之后运行却一直报错:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/base.py", line 57, in _convert value = expected_type(value)ValueError: invalid literal for int() with base 10: 'txL'During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/Users/cxxxx/Desktop/sbxjx_2.py", line 5, infile1_text=load_workbook(file1) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/reader/excel.py", line 274, in load_workbook for c in find_charts(archive, rel.target): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/chart/reader.py", line 48, in find_charts drawing = SpreadsheetDrawing.from_tree(tree) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/serialisable.py", line 84, in from_tree obj = desc.expected_type.from_tree(el) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/serialisable.py", line 84, in from_tree obj = desc.expected_type.from_tree(el) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/serialisable.py", line 100, in from_tree return cls(**attrib) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/drawing/geometry.py", line 397, in __init__ self.l = l File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/base.py", line 69, in __set__ value = _convert(self.expected_type, value) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/descriptors/base.py", line 59, in _convert raise TypeError('expected ' + str(expected_type))TypeError: expected
去stackoverflow上查了一下是openpyxl2.5版本以后的一个bug,碰到excel里有图片就会报错,解决方法有两个,删掉excel里的图片或者重新装2.4版本的openpyxl,删除图片后执行正常,最后pip3 uninstall openpyxl后手动去https://pypi.org/project/openpyxl/2.4.11/下载了2.4.11版本的openpyxl后问题彻底解决
网友评论