问题
I am using openpyxl python excel reader and writer in my Ubuntu Server
When I use following command
from openpyxl import load_workbook,Workbook
book = load_workbook(filename='/var/www/test.xlsx')
throwing error as
for _name in node:
TypeError: 'NoneType' object is not iterable
but everything fine in local system. Any one know why this is happening and how to solve this?
Update
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 202, in load_workbook
parsed_styles = read_style_table(archive)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 181, in read_style_table
p.parse()
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 53, in parse
self.parse_named_styles()
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 109, in parse_named_styles
names = self._parse_style_names()
File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 128, in _parse_style_names
for _name in node:
TypeError: 'NoneType' object is not iterable
回答1:
It looks like openpyxl isn't able to understand your list of named styles. You should first extract the .xlsx file (it's but a .zip archive with a different ending), and look for the XML file that defines styles (it's xl/styles.xml
). Verify it's well-formed XML, and not corrupted. You can do that with one of the many online XML checkers.
If that's not the culprit, you might just try to rely on openpyxl's "benevolence", delete the styles.xml, re-compress to a .zip, rename to .xlsx, and try again.
回答2:
I had the same problem, and it appeared that the path was incorrect. Open the file with Excel, and copy-paste the path from the "File" tab.
回答3:
In many cases it has to do with malformed style sheets, as previous posters have already mentioned. I have a few .xlsx files generated by Oracle SQLDeveloper. When I want to parse them with openpyxl I need to open and then save them in Excel. Otherwise I get the same error as you did. I did not compare the style sheets (before and after re-saving the file), so I can't tell you what's being fixed by saving the file in Excel. It just works in this particular case, but it may work in yours as well.
回答4:
This is a bug in openpyxml version 2.3, see: https://bitbucket.org/openpyxl/openpyxl/issues/544, it was fixed in 2.3.1.
Problem can be easily solved by upgrading to the newest version, run:
pip install openpyxl -I
This way pip ignores your current library version and gets the latest one.
回答5:
I ran into this problem today on Windows.
It turned out it was because while saving the file, under "Save as type: " I selected Strict Open XML Spreadsheet (*.xlsx)
.
It worked when I saved it as Excel Workbook (*.xlsx)
I had assumed all .xlsx
files were the same, this is apparently not the case.
来源:https://stackoverflow.com/questions/33208641/for-name-in-node-typeerror-nonetype-object-is-not-iterable