Python openpyxl load_workbook 错误:TypeError (NoneType not Iterable) 和 ValueError (Max. Value is 180) [英] Python openpyxl load_workbook Errors: TypeError (NoneType not Iterable) and ValueError (Max. Value is 180)

查看:69
本文介绍了Python openpyxl load_workbook 错误:TypeError (NoneType not Iterable) 和 ValueError (Max. Value is 180)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 Windows XP 笔记本电脑上安装了 Python 3.4.1.我得到了 openpyxl 包(现在不记得是哪个版本了,我想是 2.1)并且我一直在努力,编写自定义代码以根据需要在我的工作场所修改 Excel 文档.

So I had Python 3.4.1 installed on a Windows XP laptop. I got the openpyxl package (don't remember now which version, I think 2.1) and I was chugging along fine, writing custom code to modify Excel documents as needed at my workplace.

然后我格式化了我的笔记本电脑(出于工作相关的原因)并安装了 Windows 7.我再次获得了 Python 3.4.1.我 pip 安装了 openpyxl(在我的命令提示符中是pip install openpyxl")——这次绝对是 2.1 版.然后我尝试打开我之前的一些工作簿.

Then I formatted my laptop (for work-related reasons) and installed Windows 7. I got hold of Python 3.4.1 again. I pip installed openpyxl ("pip install openpyxl" in my command prompt) - definitely version 2.1 this time. I then tried opening some of my earlier workbooks.

这是在 IDLE GUI 界面中 - 不是在脚本或任何东西中.我只是输入(在正确导入 openpyxl->load_workbook 之后):

This was in the IDLE GUI interface - not in a script or anything. I just typed (after properly importing openpyxl->load_workbook):

wb=load_workbook('文件名.xlsx')

wb=load_workbook('Filename.xlsx')

现在出现错误.这个文件是由 Excel 2007 创建的(在 Windows XP 中创建,在我格式化我的笔记本电脑和安装 Windows 7 之前),我以前能够在我早期的 Windows XP 配置中使用我的 openpyxl 包打开它.在尝试使用 openpyxl 打开之前,我还尝试在 MS Excel(Windows 7)中重新打开 Excel 文件并重新保存.我以前的 Windows XP 和新的 Windows 7 都是 32 位的(任何地方都没有 64 位).

And now I get errors. This file was created by Excel 2007 (created in Windows XP, prior to my formatting my laptop and installing Windows 7), which I was previously able to open just fine with my openpyxl package on my earlier Windows XP configuration. I also tried reopening the Excel file(s) in MS Excel (Windows 7) and resaving, before trying to open with openpyxl. Both my previous Windows XP and my new Windows 7 are 32 bit (no 64 bit anywhere).

我得到的错误(取决于我尝试打开的文件)是:

The errors I get (depends on which file I try to open) are:

文件编号 1 的错误:

ERROR FOR FILE No. 1:

Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
wb=load_workbook('Filename.xlsx')
File "C:\Python34\lib\site-packages\openpyxl\reader\excel.py", line 151, in load_workbook
_load_workbook(wb, archive, filename, read_only, keep_vba)
File "C:\Python34\lib\site-packages\openpyxl\reader\excel.py", line 244, in _load_workbook
wb._external_links = list(detect_external_links(rels, archive))
File "C:\Python34\lib\site-packages\openpyxl\workbook\names\external.py", line 100, in detect_external_links
Book.links = list(parse_ranges(range_xml))
File "C:\Python34\lib\site-packages\openpyxl\workbook\names\external.py", line 85, in parse_ranges
for n in safe_iterator(names, '{%s}definedName' % SHEET_MAIN_NS):
TypeError: 'NoneType' object is not iterable

2 号文件错误:

Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
wb=load_workbook('Filename.xlsx')
File "C:\Python34\lib\site-packages\openpyxl\reader\excel.py", line 151, in load_workbook
_load_workbook(wb, archive, filename, read_only, keep_vba)
File "C:\Python34\lib\site-packages\openpyxl\reader\excel.py", line 205, in _load_workbook
style_table, color_index, cond_styles = read_style_table(archive.read(ARC_STYLE))
File "C:\Python34\lib\site-packages\openpyxl\reader\style.py", line 215, in read_style_table
p.parse()
File "C:\Python34\lib\site-packages\openpyxl\reader\style.py", line 44, in parse
self.parse_cell_xfs()
File "C:\Python34\lib\site-packages\openpyxl\reader\style.py", line 191, in parse_cell_xfs
_style['alignment'] = Alignment(**alignment)
File "C:\Python34\lib\site-packages\openpyxl\styles\alignment.py", line 54, in __init__
self.textRotation = textRotation
File "C:\Python34\lib\site-packages\openpyxl\styles\hashable.py", line 54, in __setattr__
return object.__setattr__(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\openpyxl\descriptors\__init__.py", line 89, in __set__
super(Min, self).__set__(instance, value)
File "C:\Python34\lib\site-packages\openpyxl\descriptors\__init__.py", line 68, in __set__
raise ValueError('Max value is <0>'.format(self.max))
ValueError: Max value is 180

对于第二种情况,我转到 __init__.py 文件并添加一行来打印生成的值.结果是 255,即 > 180(因此出现错误).我不知道这个值代表什么 - 文档中独特样式的数量或其他什么?

openpyxl 是否有任何依赖项?我已经正确安装了 Excel(现在在 Windows 7 中),带有 Service Pack 1.我还尝试卸载 Python 3.4.1 和 openpyxl 并重新安装,三到四次.

Are there any dependencies for openpyxl? I have Excel properly installed (in Windows 7 now), with Service Pack 1. I have also tried uninstalling Python 3.4.1 and openpyxl and reinstalling, three or four times.

这里可能有什么问题?

提前感谢您的回答.

推荐答案

修复NoneType错误,清除excel中数据的格式,才能加载excel.

To fix the NoneType error, clear the format of the data in the excel, then the excel could be loaded.

这篇关于Python openpyxl load_workbook 错误:TypeError (NoneType not Iterable) 和 ValueError (Max. Value is 180)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆