Skip to content

Formula Engine

excel_model.formula_engine

render_formula() — produces Excel formula strings.

render_formula(formula_type, formula_params, ctx)

Return an Excel formula string (starting with '=') or a literal value.

Raises ValueError for unknown formula_type or KeyError for missing params.

Source code in excel_model/formula_engine.py
289
290
291
292
293
294
295
296
297
298
299
300
def render_formula(
    formula_type: str,
    formula_params: dict[str, Any],
    ctx: CellContext,
) -> str | float | int:
    """Return an Excel formula string (starting with '=') or a literal value.

    Raises ValueError for unknown formula_type or KeyError for missing params.
    """
    ft = FormulaType(formula_type)  # raises ValueError if unknown
    handler = _FORMULA_DISPATCH[ft]
    return handler(formula_params, ctx)