HotXLS Docs

Formula entry validation policy

Classic XLS and XLSX expose the same side-effect-free contract for classifying formula input before a caller changes a cell

Expression-result calls

A postfix argument list can invoke a LAMBDA expression, grouped closure or closure returned by another call. Entry validation parses the complete application, including chained applications, without changing a worksheet
A successfully parsed invocation is inspectable but has no classic BIFF token encoding; parsing or evaluation success does not imply BIFF writeback support. See invocation tokens and LAMBDA evaluation

Shared policy

TXLSFormulaEmptyStringMode =
  (xlfesmClearCell, xlfesmPreserveString);
TXLSFormulaUnknownSymbolMode =
  (xlfusmReject, xlfusmPreserve);

TXLSFormulaEntryPolicy = record
  EmptyStringMode: TXLSFormulaEmptyStringMode;
  UnknownFunctionMode: TXLSFormulaUnknownSymbolMode;
  UnknownNameMode: TXLSFormulaUnknownSymbolMode;
end;

property FormulaEntryPolicy: TXLSFormulaEntryPolicy;
Classic IXLSWorkbook and TXLSWorkbook expose the property together with TXLSXWorkbook; XLSDefaultFormulaEntryPolicy clears empty input and rejects unknown functions and unknown defined names
The workbook property is copied by value and validated atomically when assigned, so unsupported enumeration values raise EArgumentOutOfRangeException without changing the previous policy

Validation result

function ValidateFormulaEntry(Row, Col: Integer;
  const Formula: WideString): TXLSFormulaEntryValidationResult;

TXLSFormulaEntryValidationResult = record
  Issue: TXLSFormulaEntryIssue;
  Action: TXLSFormulaEntryAction;
  Symbol: WideString;
end;
Issue distinguishes no error, unknown function, unknown name, syntax error, target-format limitation, and invalid target coordinates
Action selects clear cell, store string, store formula, or reject, while Symbol identifies an unknown function or name when one was recognized

Empty text and formulas

Exact empty input returns either xlfeaClearCell or xlfeaStoreString according to EmptyStringMode
A formula that returns an empty string, such as ="", remains a formula and returns xlfeaStoreFormula when the target format can represent it
Formula text may include or omit one leading equals sign
Assigning an exact empty string through the normal Classic XLS or XLSX cell Value property now applies this mode directly: the default removes any existing value or formula, while xlfesmPreserveString replaces the cell content with a constant string whose length is zero
Null and Unassigned always clear the cell in either mode, while a real formula such as ="" remains a formula with an independently stored or calculated empty-string result
XLSX string and Variant row or column writers apply the same rule without materializing cleared holes and retain packed storage whenever the remaining values are representable there
Native XLS, XLSX, and ODS readers and XLS-to-XLSX or XLSX-to-XLS converters treat stored values as trusted input, so a file-level constant empty string survives even when the destination workbook keeps the default user-entry policy

Unknown symbols and target formats

Registered workbook-local or process-wide user functions and assigned OnUserFunction or OnUserFunctionEx callbacks count as known during validation without invoking a handler, while unregistered calls retain their function name in Symbol
Strict mode returns xlfeaReject for unknown functions or names; assigning through the normal cell Formula property rejects before changing the value, formula cache, or dependencies
Preservation mode retains the diagnostic and stores the formula through the normal cell API; Classic XLS serializes an unknown call through BIFF add-in user-function tokens and retains unknown-name text through save, reopen, and XLS/XLSX conversion
Classic XLS additionally compiles known formulas through the BIFF writer and returns xlfeiTargetFormatUnsupported when the expression cannot be represented, while XLSX accepts known modern formula functions supported by its formula model
XLSX validation recognizes LAMBDA, lexical LET callables, defined names that refer to lambdas, report placeholders, registered external workbook links, and valid qualified or unqualified structured references including nested and current-row forms
Compatibility mode can also retain unresolved external structured references for later processing, while strict mode still rejects unresolved table names

Calculation and bulk audit

A preserved unknown function that remains unhandled after lambda and user-function dispatch, or a preserved unknown name, evaluates as a Variant error with code $1D, the Excel #NAME? error; the same typed error propagates through dependent formulas and contextual evaluation
Known built-in functions that are not implemented remain distinct from an unknown call, while registering, replacing, removing, or clearing a workbook-local or process-wide user function and changing a defined-name formula invalidates stale dependency and calculation state
function AuditFormulaSymbols: TXLSFormulaSymbolIssues; overload;
function AuditFormulaSymbols(
  out AStats: TXLSFormulaSymbolAuditStats):
  TXLSFormulaSymbolIssues; overload;

TXLSFormulaSymbolIssueKind = (xlfsiUnknownFunction, xlfsiUnknownName,
  xlfsiSyntaxError);
TXLSFormulaSymbolLocationKind = (xlfslCell, xlfslDefinedName);

TXLSFormulaSymbolIssue = record
  Kind: TXLSFormulaSymbolIssueKind;
  LocationKind: TXLSFormulaSymbolLocationKind;
  Sheet: Integer;
  Row: Integer;
  Col: Integer;
  DefinedNameIndex: Integer;
  DefinedName: WideString;
  Formula: WideString;
  Symbol: WideString;
end;
TXLSWorkbook and TXLSXWorkbook provide the same bulk-audit overloads; each issue identifies an unknown function, unknown name, or syntax error together with either a worksheet cell location (LocationKind = xlfslCell) or a defined-name location (LocationKind = xlfslDefinedName), the source formula, and the unresolved symbol
The audit traverses parsed formula trees or stored BIFF tokens instead of scanning text, so function-like text inside a string is not reported; XLSX compilation uses an operation-local cache keyed by resolved formula text, worksheet, locale, defined-name generation, user-function registry generations, and callback availability
Classic XLS audits skip columns outside the worksheet's allocated column bounds, reducing scan time on sparse workbooks while preserving the reported findings and their order, including findings from defined names; empty slots inside those bounds are still checked
EntryCount reports audited formulas, UniqueFormulaCount reports formulas compiled or inspected independently, and CacheHitCount reports repeated entries served by the operation cache

Explicit worksheet-scoped defined names

Version 2.384.520 resolves an explicitly qualified defined name in the target worksheet scope even when the calling worksheet has no definition with that spelling

For example, Auxiliary!LocalOnly, 'Aux input'!LocalOnly and 'Aux''s input'!LocalOnly select the target-local definition, including when a caller-local or workbook-scoped name has the same spelling

Qualified range-based and chained names work in arithmetic and function arguments; a successful target lookup clears only its abandoned suffix diagnostic, while genuine unresolved names remain rejected under the selected entry policy

Formula spelling and defined-name scope remain intact through XLSX saving and reopening; quoted worksheet names containing an exclamation mark still require a separate lexer repair and are not included in this extension

Quoted worksheet reference boundaries

Version 2.384.522 preserves quoted worksheet names containing ! and doubled apostrophes through formula entry, evaluation and saving, including worksheet-scoped defined names, individual cells, ranges and function arguments

The actual separator outside the quoted name determines the target, so adding a worksheet with a longer matching name cannot redirect an existing quoted reference

For example, 'A!B'!LocalOnly resolves the name on worksheet A!B, while 'O''Brien!X'!A2 retains the escaped apostrophe and separator inside its worksheet name

Quoted worksheet pairs also distinguish single cells from rectangular ranges: with worksheet A!B followed by worksheet C, SUM('A!B:C'!A2) sums cell A2 across that sheet interval, while SUM('A!B:C'!A1:A2) sums the actual rectangular range

Stored formulas retain their input spelling across saving and reopening, ordinary string literals retain their exclamation marks, and genuine missing names, missing worksheets and malformed extra separators retain strict refusal behavior

Existing external-workbook syntax controls retain their previous behavior; these local-reference checks do not establish unrestricted external-link execution

No worksheet mutation

Validation does not create or edit a cell, change cached values, update the dependency graph, mark the workbook dirty, or invoke a registered user-function handler
Direct validation remains mutation-free; normal formula assignment applies the same decision internally and commits only after validation and target-format preparation succeed

Delphi example

Policy := Workbook.FormulaEntryPolicy;
Policy.UnknownFunctionMode := xlfusmReject;
Policy.UnknownNameMode := xlfusmReject;
Workbook.FormulaEntryPolicy := Policy;

Validation := Sheet.ValidateFormulaEntry(4, 2, FormulaText);
if Validation.Action = xlfeaStoreFormula then
  Sheet.Cells[4, 2].Formula := FormulaText;

Issues := Workbook.AuditFormulaSymbols(Stats);
for I := 0 to High(Issues) do
  if Issues[I].Kind = xlfsiUnknownFunction then
    LogUnknownSymbol(Issues[I].Symbol);

See also

Contextual formula evaluation
Excel calculation engine
Classic XLS additional API members
Advanced XLSX API members