Allow advanced ranges

Issue #397 resolved
jarda-wien created an issue

MS Excel can work with special range notations like 1:1 for the entire first row (column independent) or A:A for the first column (row independent).

The iter_rows() function throws an "Invalid cell coordinates exception" when trying this.

I propose to add code to support this kind of notation.

BR Jaroslav

Comments (5)

  1. CharlieC

    I've been thinking of adding this myself but using the slicing notation: ws['A'] or ws[1] rather than iter_rows() which is really implementation. Feel to pick this up for the 2.2 branch.

    FWIW ws.rows[1] or ws.columns[1] will already do want you need.

  2. jarda-wien reporter

    ws.rows and ws.columns unfortunately don't work with use_iterators=True if I understand it correctly. Trying it fails with TypeError: 'generator' object is not subscriptable.

    For now I am using this workaround to get the first row (header):

    i = 0
    header = []
    for row in ws.iter_rows():
                i += 1
                if i > 1:
                for cell in row:
  3. CharlieC

    You didn't say you were using read-only mode. ws.rows works fine (though it returns a generator, so just turn it into a tuple) but ws.columns will probably fail.

    You should be using get_squared_range(1, 1, None, 1)

    FWIW I'm working on changes to the internals for this at the moment but that shouldn't affect the API.

  4. Log in to comment