'NoneType' object has no attribute 'parent' accessing the Fill property of an empty cell
Created originally on Bitbucket by memoselyk (Julian Trevino Mondragon)
Preconditions
Create an empty workbook and add only content to cell B2.
Steps to reproduce
- Open the workbook from precondition
- Attempt to get the
fill
property of a cell obtained by iterating over rows fromworkbook.rows
.
Sample snippet showing the failure,
#!python
from openpyxl import load_workbook
wb = load_workbook("test_file.xlsx", read_only=True)
ws = wb.get_active_sheet()
for ri, row in enumerate(ws.rows):
for rc, cell in enumerate(row):
col = chr(rc + ord('A'))
try:
print "%s, %d - %s" % (col, ri + 1, cell.fill)
except Exception as err:
print "%s, %d - ERROR %s" % (col, ri + 1, err)
Observed results
Attemps to obtain the fill
properties of cells A1, A2, B1 faill with error:
File "C:\Python27\lib\site-packages\openpyxl\cell\read_only.py", line 82, in fill
_id = self.style_array.fillId
File "C:\Python27\lib\site-packages\openpyxl\cell\read_only.py", line 65, in style_array
return self.parent.parent._cell_styles[self._style_id]
AttributeError: 'NoneType' object has no attribute 'parent'
Expected results
I presume that such cells should, at least, return a None value instead of raising an exception.