TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Issue #367 resolved
Sergey Pikhovkin
created an issue
class Worksheet(object):
    ...

    def iter_rows(self, range_string='', row_offset=0, column_offset=1):
        ...
        return self.get_squared_range(min_col + column_offset,
                                      min_row + row_offset,
                                      max_col + column_offset,
                                      max_row + row_offset)

If call load_workbook('filename', use_iterators=True) with use_iterators=True, then max_col and max_row are equal to None, causing error

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Comments (9)

  1. Sergey Pikhovkin reporter

    ws.calculate_dimensions() returns ValueError: Worksheet is unsized, cannot calculate dimensions in 2.0 and 2.1, but iter_rows runs in 2.0 with use_iterators=True (for load_workbook)

  2. Charlie Clark

    Yeah, 2.1 harmonised the code base for standard and read-only worksheets but I forgot to take into account that not all software writes how big a worksheet is – it's not a requirement. In standard workbooks it doesn't matter because the values are set by reading the worksheet

    Patching something like the following for max_col and max_row should solve the problem:

    if max_col is not None:
        max_col + column_offset
    if max_row is not None:
        max_row + row_offset
    return get_squared_range(min_col + column_offset, min_row + row_offset, max_col, max_row)
    

    This should be the same as using get_squared_range directly: ws.get_squared_range(1, 1, None, None)

  3. Sergey Pikhovkin reporter

    Yes, that's works

            if max_col is not None:
                max_col += column_offset
            if max_row is not None:
                max_row += row_offset
    
            return self.get_squared_range(min_col + column_offset, min_row + row_offset, max_col, max_row)
    
  4. Log in to comment