Attempting to access font attribute of existing cell with default formatting causes error

Issue #532 resolved
Jordan Macdonald
created an issue

One of my scripts which uses openpyxl to read data from an existing spreadsheet has stopped working after I upgraded to 2.3. The error occurs when I try to access the font property of a cell in order to check that it is not struck-through (strike-through being used to flag a cell to be skipped). The relevant section of the stack trace:

  File "C:\Users\jordan_macdonald\[REDACTED]", line 27, in __init__
    if (cell is None or cell.value is None or cell.font.strike):
  File "C:\Python27\lib\site-packages\openpyxl-2.3.0b2-py2.7.egg\openpyxl\cell\read_only.py", line 81, in font
    _id = self.style_array.fontId
AttributeError: 'NoneType' object has no attribute 'fontId'

Other than the possible strike-through, the cell in question is has no formatting specified in the source spreadsheet; I presume the error is caused because the new style management code fails to specify a default Font object for cells in the default format.

Comments (5)

  1. Charlie Clark

    Thanks for the report. Can you provide a sample file to help investigate?

    2.3 contains a lot of work to reduce the memory impact of individual cell styles. Part of this, of course, is using None wherever possible.

  2. Jordan Macdonald reporter

    Minimal demonstration script and test document attached. Complete traceback:

    Traceback (most recent call last):
      File "C:\Users\jordan_macdonald\[REDACTED]\err.py", line 10, in <module>
        if (cell is None or cell.value is None or cell.font.strike):
      File "C:\Python27\lib\site-packages\openpyxl-2.3.0b2-py2.7.egg\openpyxl\cell\read_only.py", line 81, in font
        _id = self.style_array.fontId
    AttributeError: 'NoneType' object has no attribute 'fontId'
    
  3. Log in to comment