OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
OpenXLSX::XLFormulaEngine Class Reference

#include <XLFormulaEngine.hpp>

Public Member Functions

 XLFormulaEngine ()
 ~XLFormulaEngine ()
 XLFormulaEngine (const XLFormulaEngine &)=delete
XLFormulaEngine & operator= (const XLFormulaEngine &)=delete
 XLFormulaEngine (XLFormulaEngine &&)=delete
XLFormulaEngine & operator= (XLFormulaEngine &&)=delete
void setAstCacheEnabled (bool enabled) noexcept
bool astCacheEnabled () const noexcept
void setAstCacheCapacity (std::size_t capacity) noexcept
std::size_t astCacheCapacity () const noexcept
std::size_t astCacheSize () const
void clearAstCache ()
XLCellValue evaluate (std::string_view formula, const XLCellResolver &resolver={}, XLFormulaDiagnosticReporter *reporter=nullptr) const
 Evaluate a formula string.
XLCellValue evaluate (std::string_view formula, XLEvalSession &session, XLFormulaDiagnosticReporter *reporter=nullptr) const
 Evaluate with a full evaluation session (names, current cell, depth, …).
XLFormulaArg evaluateArray (std::string_view formula, const XLCellResolver &resolver={}, XLFormulaDiagnosticReporter *reporter=nullptr) const
 Evaluate a formula preserving full array/range shape (Phase B spill path).
XLFormulaArg evaluateArray (std::string_view formula, XLEvalSession &session, XLFormulaDiagnosticReporter *reporter=nullptr) const
 Session-aware array evaluation (FILTER/UNIQUE/SORT/SEQUENCE, range arithmetic, …).

Static Public Member Functions

static XLCellResolver makeResolver (const XLEvaluationContext &context)
 Create a CellResolver that reads live values from an evaluation context.
static XLCellResolver makeResolver (const XLWorksheet &wks)
 Create a CellResolver that reads live values from an XLWorksheet.
static XLCellResolver makeResolver (const IXLCellProvider &provider)
 Create a CellResolver that reads live values from an IXLCellProvider interface.
static XLFormulaArg expandRange (std::string_view rangeRef, const XLCellResolver &resolver)
 Expand an A1 cell/range reference using the given resolver.

Friends

class XLFormulaParser

Constructor & Destructor Documentation

◆ XLFormulaEngine() [1/3]

XLFormulaEngine::XLFormulaEngine ( )

◆ ~XLFormulaEngine()

XLFormulaEngine::~XLFormulaEngine ( )
default

◆ XLFormulaEngine() [2/3]

OpenXLSX::XLFormulaEngine::XLFormulaEngine ( const XLFormulaEngine & )
delete

◆ XLFormulaEngine() [3/3]

OpenXLSX::XLFormulaEngine::XLFormulaEngine ( XLFormulaEngine && )
delete

Member Function Documentation

◆ astCacheCapacity()

std::size_t OpenXLSX::XLFormulaEngine::astCacheCapacity ( ) const
inlinenodiscardnoexcept

◆ astCacheEnabled()

bool OpenXLSX::XLFormulaEngine::astCacheEnabled ( ) const
inlinenodiscardnoexcept

◆ astCacheSize()

std::size_t XLFormulaEngine::astCacheSize ( ) const
nodiscard

Number of cached ASTs.

◆ clearAstCache()

void XLFormulaEngine::clearAstCache ( )

Drop all cached parse trees.

◆ evaluate() [1/2]

XLCellValue XLFormulaEngine::evaluate ( std::string_view formula,
const XLCellResolver & resolver = {},
XLFormulaDiagnosticReporter * reporter = nullptr ) const
nodiscard

Evaluate a formula string.

Parameters
formulaThe formula text (with or without leading '=').
resolverCallback to look up cell values. May be empty if the formula contains no cell references.
Returns
The computed XLCellValue; an error value on evaluation failure.
Note
Prefer pairing with an XLEvaluationContext via makeResolver(context) so formula code depends only on the sheet-read port, not a concrete worksheet type:
engine.evaluate("=A1+B1", XLFormulaEngine::makeResolver(ctx));
static XLCellResolver makeResolver(const XLEvaluationContext &context)
Create a CellResolver that reads live values from an evaluation context.
Definition XLFormulaEngine.cpp:988
Evaluation context backed by a live worksheet (and its workbook for sheet-qualified refs).
Definition XLEvaluationContext.hpp:75

◆ evaluate() [2/2]

XLCellValue XLFormulaEngine::evaluate ( std::string_view formula,
XLEvalSession & session,
XLFormulaDiagnosticReporter * reporter = nullptr ) const
nodiscard

Evaluate with a full evaluation session (names, current cell, depth, …).

Multi-cell array results are reduced via implicit intersection (top-left). Use evaluateArray() when the full spill shape is required.

◆ evaluateArray() [1/2]

XLFormulaArg XLFormulaEngine::evaluateArray ( std::string_view formula,
const XLCellResolver & resolver = {},
XLFormulaDiagnosticReporter * reporter = nullptr ) const
nodiscard

Evaluate a formula preserving full array/range shape (Phase B spill path).

◆ evaluateArray() [2/2]

XLFormulaArg XLFormulaEngine::evaluateArray ( std::string_view formula,
XLEvalSession & session,
XLFormulaDiagnosticReporter * reporter = nullptr ) const
nodiscard

Session-aware array evaluation (FILTER/UNIQUE/SORT/SEQUENCE, range arithmetic, …).

◆ expandRange()

XLFormulaArg OpenXLSX::XLFormulaEngine::expandRange ( std::string_view rangeRef,
const XLCellResolver & resolver )
staticnodiscard

Expand an A1 cell/range reference using the given resolver.

Public so session-aware functions (INDIRECT, OFFSET) can build LazyRanges.

◆ makeResolver() [1/3]

XLCellResolver XLFormulaEngine::makeResolver ( const IXLCellProvider & provider)
staticnodiscard

Create a CellResolver that reads live values from an IXLCellProvider interface.

Parameters
providerThe cell data provider (can be an XLWorksheet or mock provider).
Returns
A resolver callable capturing a reference to provider.
Note
The returned resolver is only valid while provider is alive.

◆ makeResolver() [2/3]

XLCellResolver XLFormulaEngine::makeResolver ( const XLEvaluationContext & context)
staticnodiscard

Create a CellResolver that reads live values from an evaluation context.

Parameters
contextThe abstract sheet-read port.
Returns
A resolver callable capturing a reference to context.
Note
The returned resolver is only valid while context is alive.

◆ makeResolver() [3/3]

XLCellResolver XLFormulaEngine::makeResolver ( const XLWorksheet & wks)
staticnodiscard

Create a CellResolver that reads live values from an XLWorksheet.

Parameters
wksThe source worksheet.
Returns
A resolver callable capturing a reference to wks.
Note
The returned resolver is only valid while wks is alive.
Prefer XLWorksheetEvaluationContext + evaluate(formula, context) for new code.

◆ operator=() [1/2]

XLFormulaEngine & OpenXLSX::XLFormulaEngine::operator= ( const XLFormulaEngine & )
delete

◆ operator=() [2/2]

XLFormulaEngine & OpenXLSX::XLFormulaEngine::operator= ( XLFormulaEngine && )
delete

◆ setAstCacheCapacity()

void XLFormulaEngine::setAstCacheCapacity ( std::size_t capacity)
noexcept

Max distinct formulas retained in the cache (default 512). LRU-ish drop of arbitrary entry when full.

◆ setAstCacheEnabled()

void OpenXLSX::XLFormulaEngine::setAstCacheEnabled ( bool enabled)
inlinenoexcept

Enable/disable parse-tree caching (default: enabled).

◆ XLFormulaParser

friend class XLFormulaParser
friend

The documentation for this class was generated from the following files: