Method SetDynamicFormula
- Namespace
- DocWright.Spreadsheet
- Assembly
- DocWright.Spreadsheet.dll
SetDynamicFormula(string, string)
Enters a dynamic array formula in a cell, as Excel 365 enters any formula (Phase 210): its result spills from the
cell as far as it reaches when the workbook is calculated, or the cell shows #SPILL! when a cell it would
fill holds something. What the cell spilled before goes with the formula it held.
public void SetDynamicFormula(string reference, string formula)
Parameters
referencestringThe cell, such as
B4.formulastringThe formula, with or without its leading
=, as Excel stores it: English function names, commas between arguments, a newer function with its prefix (_xlfn._xlws.SORT(A1:A9),_xlfn.UNIQUE(A1:A9)).
Remarks
The workbook is given the cell metadata that marks a dynamic array when it has none. Excel 2019 and earlier show such a formula as a legacy array formula over the cells it spilled into.
Exceptions
- ArgumentNullException
referenceorformulais null.- ArgumentException
referenceis not a cell reference inside the worksheet grid, or the formula is empty or too long.- InvalidOperationException
The sheet is not a worksheet.
- UnsupportedFeatureException
The cell is part of a legacy array formula, or is a header or totals cell of a table; or the workbook's cell metadata holds no entry for dynamic arrays and was written for something else.
- InvalidDocumentException
The sheet's part is malformed.