Why does a get_squared_range object appear?

Issue #487 invalid
Chris Vargo (chrisjvargo) created an issue

Just loading in an excel file using openpyxl.

from openpyxl import load_workbook
filename = 'test.xlsx'
wb = load_workbook(filename, use_iterators=True)
ws = wb.get_sheet_by_name('Sheet1')

print(ws['A1'])
>>> <generator object get_squared_range at 0x102c0b5a0>

The documentation suggests an get_squared_range object is generated for blank cells, but the cell is not empty. It should return '1234'

Comments (12)

  1. CharlieC

    This is mainly historical due to the way read-only mode was designed, where accessing individual cells is not very common.

  2. Chris Vargo (chrisjvargo) reporter

    Thanks. This works fine:

    from openpyxl import load_workbook
    filename = 'test.xlsx'
    wb = load_workbook(filename)
    ws = wb.get_sheet_by_name('Sheet1')
    

    print(ws['A1'])

  3. CharlieC

    That's normal use, though wb['Sheet1'] is preferable (I'd like to drop as many get* methods as possible.

    If you have a very large file the read_only=True makes sense and I suppose the API should be cleaned up to return to match standard worksheets as much as possible, but really you're most likely to be getting a range anyway.

  4. Chris Vargo (chrisjvargo) reporter

    Is there a donation link? I really did find the module incredibly helpful.

  5. Log in to comment