Too many EmptyCell's retrieved from ReadOnlyWorksheet
Created originally on Bitbucket by Pravin Kumar
One extra EmptyCell is retrieved when an empty range is selected. I'm not sure why any cells are retrieved at all, I thought an empty set should be returned. This only happens on the attached workbook, which is a stripped-down version of a production one I am working with. I created this workbook with Excel 2016.
Here is a minimal example, applied on the attached excel workbook:
#!python
import openpyxl
wb = openpyxl.load_workbook(filename='test_empty.xlsx', read_only=True)
ws = wb['Main']
# Should be length 2, but is length 3
ref = 'D2:E2'
print(ref)
print([x.value for x in ws[ref][0]])
print(len(ws[ref][0]))
# Should be length 5 and is length 5
ref2 = 'A2:E2'
print(ref2)
print([x.value for x in ws[ref2][0]])
print(len(ws[ref2][0]))
Outputs
#!python
D2:E2
[None, None, None]
3
A2:E2
['a', 'b', None, None, None]
5
openpyxl 2.4.8 (pip installation) Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Windows 10, Excel 2016
Screenshot of test_empty.xlsx:
Screenshot from my actual project, debugged in PyCharm:
I'm happy to have a go at fixing this bug, if you can give me an idea of where to start. Thanks
Attachments: test_empty.xlsx