Why doesn't MergedCell have "is_date"?

93 views
Skip to first unread message

Martin Thoma

unread,
Mar 1, 2021, 2:59:34 PM3/1/21
to openpyxl-users
Hiho,

I've just noticed that MergedCell seems not the have "is_date":

>>> from openpyxl.cell import MergedCell, Cell
>>> MergedCell.is_date
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: type object 'MergedCell' has no attribute 'is_date'
>>> Cell.is_date <property object at 0x7f676e7c8bd0>

I don't know what MergedCell is. I've just noticed that mypy complained about this in my codebase. Would it make sense to add is_date to MergedCell?

Best regards,
Martin

Charlie Clark

unread,
Mar 2, 2021, 4:28:30 AM3/2/21
to openpyxl-users

MergedCells only exist because Excel makes a mess when formatting ranges of merged cells. Normally when you merge cells, all but the top-left cell are deleted. However, if the range has a border then Excel creates cells for the borders. In the GUI this is less of a problem because the user cannot do anything in those cells, but for any library handling the worksheet the cells are just normal cells. This is why we introduced merged cells whose only purpose is to mimic Excel's way of dealing with borders, whilst at the same time making it clear to client code that the cells are not relevant: the value is always None and the cells have only the attributes they need to preserve formatting. In general, you don't need to think about them, just put it down to yet another annoying thing in Mypy…

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Waldlehne 23
Düsseldorf
D- 40489
Mobile: +49-178-782-6226

Reply all
Reply to author
Forward
0 new messages