Python openpyxl load_workbook Errors: TypeError (NoneType not Iterable) and ValueError (Max. Value is 180)
Question: 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.

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.

**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('Filename.xlsx')

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:

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
    

ERROR FOR FILE No. 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
    

**For the second case, I went to the __init__.py file and added a line to
print the value generated. It turned out to be 255, which is > 180 (hence the
error). I have no clue what this value represents - number of unique styles in
the document or something?**

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.

What could be the problem here?

Thanks in advance for any answers.


Answer: For the second, you have self.textRotation set to 255. That's where the max =
180 (degrees) comes from. In alignment.py, the min/max for textRoation is
0-180. This restriction was added in 2.1. (I find this restriction dubious, as
there are 360 degrees.)

EDIT: In a more general sense, you're just trying to read an excel file. So,
these are likely bugs.

