HotXLS Docs

Contextual formula evaluation

Classic XLS and XLSX worksheets expose the same read-only API for evaluating formula text as though it had been entered in a chosen one-based row and column

LAMBDA expression invocation

Invoke a LAMBDA expression, grouped closure, closure-producing selector or returned closure with a postfix argument list, including chained calls such as LAMBDA(x,LAMBDA(y,x+y))(2)(3), which returns 5
Arguments are evaluated in the caller's scope before lexical bindings and parameters are installed; this does not provide deferred argument-expression evaluation. Inline, named and LET-bound calls preserve returned reference identity for consumers such as ISREF and COUNTBLANK
Typed errors, array bounds, cancellation and configured recursion, step and memory limits retain their evaluation contracts. OOXML preserves the authored formula text; an expression-result invocation represented by SA_APPLY has no classic BIFF encoding and cannot be saved as a BIFF formula. Ordinary named calls retain their existing encoding path
See invocation token inspection for the lower-level representation

One-shot evaluation

function EvaluateFormulaAt(Row, Col: Integer;
  const Formula: WideString): TXLSFormulaEvaluationResult; overload;

function EvaluateFormulaAt(Row, Col: Integer;
  const Formula: WideString;
  ReferenceStyle: TXLSFormulaReferenceStyle;
  const Options: TXLSFormulaEvaluationOptions): TXLSFormulaEvaluationResult; overload;
The worksheet supplies the local-name, unqualified-reference, table, and external-link context without changing the active sheet, selection, cell model, formula cache, dirty state, or dependency graph
xlfrsA1 preserves absolute and mixed references while resolving relative references from the target cell; xlfrsR1C1 resolves relative offsets directly from that target
CELL without an explicit reference inspects the supplied target cell; use $A$1 to inspect the fixed first cell from any target, while A1 resolves relative to that target under the A1 context contract
Model-backed CELL metadata and INFO("recalc") also work through read-only workbook views without changing their generation or stored formula caches; CELL("width",reference) retains its one-row, two-column array, and unclassified custom formats return xlfeUnsupportedFunction instead of a fabricated format code; see CELL and INFO metadata for the complete headless and locale boundaries

Typed results

Detached evaluation preserves blank Null, Empty and omitted results by default; set TXLSFormulaEvaluationOptions.ProjectBlankResults=True to project completed scalar values and blank elements of completed Variant arrays to numeric zero while retaining empty text, Boolean values, dates, array bounds and typed errors

Raw source cells and intermediate references retain blank identity for predicates and aggregate functions; these APIs return completed values and do not reproduce the Range-object return convention of Excel automation Worksheet.Evaluate

FORMULATEXT inspects stored formula metadata through both worksheet engines and read-only views without calculating the inspected target; GETPIVOTDATA evaluates a detached snapshot of a local PivotTable's existing cache and respects evaluation budgets and cancellation; missing visible aggregates remain typed #REF! values, while incomplete or unsupported Pivot models return xlfeUnsupportedFunction; see formula text inspection and visible Pivot data for storage, array, and cache boundaries
TXLSFormulaEvaluationResult returns Status, the original typed Value, IsVolatile, and a stable Issue record containing status, native code, and message
TXLSFormulaEvaluationStatus = (xlfeOk, xlfeInvalidArgument,
  xlfeWorksheetUnavailable, xlfeParseError, xlfeUnsupportedFunction,
  xlfeCircularReference, xlfeExternalReferenceDenied, xlfeCancelled,
  xlfeResourceLimit, xlfeFailed, xlfeUnsafeFunctionDenied);

TXLSFormulaEvaluationIssue = record
  Status: TXLSFormulaEvaluationStatus;
  NativeCode: Integer;
  Message: WideString;
end;
    
Formula values such as #DIV/0!, #REF!, empty strings, arrays, Boolean values, and dates remain distinguishable values; parse failures, unsupported functions, circular references, denied external references, denied unsafe callbacks, cancellation, invalid arguments, unavailable worksheets, and resource exhaustion use explicit API statuses. Issue.NativeCode carries the underlying engine error code and Issue.Message the human-readable description when Status is not xlfeOk

Reusable immutable templates

function CreateFormulaEvaluationTemplate(Row, Col: Integer;
  const Formula: WideString;
  ReferenceStyle: TXLSFormulaReferenceStyle): IXLSFormulaEvaluationTemplate;
A template compiles the formula once at its anchor and exposes EvaluateAt and EvaluateAtWithOptions for repeated evaluation at different target cells
Ordinary A1 and R1C1 formulas reuse the compiled tree directly; A1 structured references whose meaning depends on the target table row are resolved and compiled for that target context
Templates keep no writable worksheet state, safely report xlfeWorksheetUnavailable after workbook destruction, and fall back to context-aware recompilation when workbook changes make the original compiled context stale

Resource, external-reference, and callback options

AllowExternalReferencesDefaults to true but permits only explicitly registered workspace targets or file-local caches and never performs implicit file or network access
AllowUnsafeFormulaCallbacksDefaults to false and blocks dangerous function names from reaching a user-function registry or callback before any argument is evaluated; denial returns xlfeUnsafeFunctionDenied
AllowExternalDataFunctionsDefaults to false. With it set, WEBSERVICE, RTD and DDE reach the user-function registry or callback; the dangerous names stay governed by AllowUnsafeFormulaCallbacks. The workbook property of the same name feeds this field for a recalculation pass. Inside the calculator the flag lives on TXLSCalcEvalState, which carries the same AllowExternalDataFunctions member for a detached evaluation, and the calculator's own switch can only widen - never narrow - what the options allow.
CancelFlagOptional Boolean pointer checked before and after evaluation
MaxFormulaLengthDefaults to 8192 UTF-16 code units
MaxEvaluationStepsDefaults to 1,000,000 syntax-item evaluations
MaxRecursionDepthDefaults to 256 nested formula evaluations
MaxArrayBytesDefaults to 64 MiB for generated array payloads
ProjectBlankResultsDefaults to False to preserve blank detached results; True requests completed-value zero projection without changing source cells or intermediate operands
A zero or negative maximum disables that per-call limit; the workbook-wide array memory policy still applies, and reaching an enabled limit returns xlfeResourceLimit after releasing temporary evaluation state
The overload that accepts explicit options treats AllowUnsafeFormulaCallbacks as authoritative for that call; default one-shot and template evaluation inherit the workbook property of the same name

Delphi example

Template := Sheet.CreateFormulaEvaluationTemplate(2, 2,
  '=R[-1]C[-1]+1', xlfrsR1C1);

Result := Template.EvaluateAt(2, 2);
if Result.Status = xlfeOk then
  UseValue(Result.Value);

Options := XLSDefaultFormulaEvaluationOptions;
Options.MaxEvaluationSteps := 10000;
Result := Template.EvaluateAtWithOptions(20, 4, Options);

C++Builder example

Lxcalc::_di_IXLSFormulaEvaluationTemplate evalTemplate =
  sheet->CreateFormulaEvaluationTemplate(1, 1,
    WideString(L"=ROW()+COLUMN()"), Lxcalc::xlfrsA1);

Lxcalc::TXLSFormulaEvaluationResult result =
  evalTemplate->EvaluateAt(7, 8);

The direct regular expression backend API documents per-instance matching, replacement, statuses and caller budgets

REGEX formulas share the current evaluation context's work, memory, and cancellation controls, including PCRE2 workspace and output allocations; cancellation or a resource limit yields an explicit status without a partial extraction or replacement result

GROUPBY and PIVOTBY summarize detached arrays or worksheet-range snapshots in the current context, including captured Lambda environments, grouping indexes, callback vectors, and output storage; resource limits and cancellation return explicit statuses without changing worksheet data, caches, or layout

See also

TXLSWorksheet.Calculate method
IXLSWorkbook.Calculate method
Excel calculation engine