“@” symbol appearing after inserting IF formula into excel using Openpyxl

Answering my own question here. Thanks to JvdV for putting me on the right path.

In this answer I found what solved my question. I added this line before saving the excel file in my example code:

ws.formula_attributes['E9'] = {'t': 'array', 'ref': "E9:E9"}

This essentially sets the formula in cell ‘E9’ to be read as an array formula, which is shown in Excel by having the formula between curly braces ({}). In older versions of Excel this is done by, pressing ctrl-shift-enter when entering the formula. Note that writing these curly braces in the formula string does not work.

If anyone knows how the ‘ref’ part works, feel free add this in the comments.

Leave a Comment