I'm using openpyxl to create worksheets that contain some custom Excel formulas. One of the custom Excel formulas returns an array, but I don't know the size of the array (i.e. number of rows or columns) ahead of time.
Suppose this is the custom Excel formula:
=GETVALUES(<some input>)
If I use this formula in Excel 365, the array will dynamically resize based on the return dimension of GETVALUES
, as desired. But if I set the formula in openpyxl (e.g. ws["A1"].value = '=_xldudf_GETVALUES(<some input>)'
) then open this workbook in Excel 365, I get an @ sign after the equal sign.
I saw this article that suggests setting the formula_attributes
: the t
field to array
and the ref
field to a cell range. Since I don't know the size of the returned array, I don't think I'll know what to set for the ref
field.
Is there a way to set the formula in openpyxl (without knowing the size of the returned array) such that Excel 365 will display the entire array dynamically? If not, is there another Excel API for Python that would be able to handle this?