Index out of range when reading with Openpyxl

I am trying to open a .xlsx file with Openpyxl using the "Optimized Reader" hints from the documentation:

# -*- coding: iso-8859-1 -*-
from openpyxl import load_workbook

wb = load_workbook(filename = r'/path/to/the/file.xlsx', use_iterators = True)

      

This gives me the following error:

Traceback (most recent call last):
  File "/home/me/test.py", line 5, in <module>
    wb = load_workbook(filename = r'/path/to/the/file.xlsx', use_iterators = True)
  File "/usr/local/lib/python2.6/dist-packages/openpyxl/reader/excel.py", line 151, in load_workbook
    _load_workbook(wb, archive, filename, read_only, keep_vba)
  File "/usr/local/lib/python2.6/dist-packages/openpyxl/reader/excel.py", line 240, in _load_workbook
    wb._named_ranges = list(read_named_ranges(archive.read(ARC_WORKBOOK), wb))
   File "/usr/local/lib/python2.6/dist-packages/openpyxl/reader/workbook.py", line 160, in read_named_ranges
     named_range.scope = workbook.worksheets[int(location_id)]
IndexError: list index out of range

      

I also tried to use flags (keep_vba = True|False, guess_types = True|False, data_only = True|False)

with every combination. The same error.

The .xlsx file I am trying to open contains 13 worksheets, there is no sheet with more than 200 lines, so I guess this is not a size issue. I can't edit anything in this .xlsx file, I don't have permission, this is a file to read for me.

I am using Python 2.6 on 64bit Debian Squeeze and Openpyxl version is 2.1.0. If I try to open another file (empty test file), it works fine (no script runs on error).

So my question is, what is wrong with the .xlsx file I'm trying to open?

+3


source to share


1 answer


The problem stems from the specific names / ranges being used. I've seen this one more file, but not really sure what is running it. Can you please submit a bug, preferably with a sample file, as this will make it much easier to track down the issue.



The 2.1 branch should fix this if you can try checking out. As far as I can tell, the problem is with using certain names from other books, or when using some reserved names for print areas, etc. Such definitions are likely to be lost when processing the openpyxl file, but should not be affected by the data itself

0


source







All Articles