Array formulas not working

665 views
Skip to first unread message

Conny

unread,
Aug 4, 2019, 2:09:13 PM8/4/19
to openpyxl-users
Hi,

I am trying to insert an array formula {} or CTRL+SHIFT+ENTER but I cannot do it.

ws["A1"] = "=B4:B8"
ws.formula_attributes['A1'] = {'t': 'array', 'ref': "B4:B8"}

If I use the above formula Excel tries to repair the workbook.

If i use only ws.formula_attributes['A1'] = {'t': 'array', 'ref': "B4:B8"} no formula is added to the worksheet.

Is there no way to add array formulas with OpenPyXL?

awe...@gmail.com

unread,
Aug 9, 2019, 2:15:21 PM8/9/19
to openpyxl-users
Conny,
Yeah, this isn't really documented well. The 'ref' attribute in the formula_attributes for 'A1' should point at where the formula is displayed.  So in this case, I'm assuming you want to display the values of B4:B8 in the cells A1:A5.  To do this you would do the following.

ws["A1"] = "=B4:B8"
ws.formula_attributes['A1'] = {'t': 'array', 'ref': "A1:A5"}

I hope this helps.

Conny

unread,
Aug 10, 2019, 7:06:07 AM8/10/19
to openpyx...@googlegroups.com
That did the trick! Thank you.

--
You received this message because you are subscribed to the Google Groups "openpyxl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpyxl-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpyxl-users/15ae1730-b47f-4560-a376-400fa55280d1%40googlegroups.com.

david....@gmail.com

unread,
May 8, 2020, 8:54:19 PM5/8/20
to openpyxl-users
Could someone please explain the concept of the Tokenizer in plain English? Like, what is the ultimate purpose of it in layman's terms? And I can't find formula_attributes. Does this still exist? I'm using Openpyxl to put array formulas in a workbook. I'm getting the formulas in the workbook just fine, but when I open the workbook the formulas won't work unless I delete the brackets. Will a "tokenizer" help? lol
Reply all
Reply to author
Forward
0 new messages