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

Functions

double toDouble (const XLCellValue &v)
bool isNumeric (const XLCellValue &v)
bool isEmpty (const XLCellValue &v)
bool isError (const XLCellValue &v)
std::string toString (const XLCellValue &v)
XLCellValue makeError (std::string_view token)
XLCellValue errValue ()
XLCellValue errDiv0 ()
XLCellValue errNA ()
XLCellValue errNum ()
XLCellValue errRef ()
XLCellValue errName ()
XLCellValue errCirc ()
std::string strTrim (std::string s)
bool tryParseNumericString (std::string_view s, double &out)
 Parse a fully-numeric string (optional leading/trailing space) to double.
XLCellValue coerceToNumber (const XLCellValue &v, bool blankAsZero=true)
 Excel-style scalar numeric coercion for math functions and arithmetic.
XLCellValue coerceArgScalar (const XLFormulaArg &arg, bool blankAsZero=true)
 Coerce the first scalar of an argument (implicit intersection / top-left).
XLCellValue firstError (const XLFormulaArg &arg)
 First error value found in argument cells (Excel left-to-right, top-to-bottom).
XLCellValue firstError (const std::vector< XLFormulaArg > &args)
std::vector< double > numerics (const std::vector< XLFormulaArg > &args)
std::vector< double > numerics (const XLFormulaArg &arg)
std::vector< double > numericsOrError (const std::vector< XLFormulaArg > &args, XLCellValue &outError)
 Like numerics(), but if any cell is an Error, sets outError and returns {}.
std::vector< double > numericsOrError (const XLFormulaArg &arg, XLCellValue &outError)
void setFormulaRandomSeed (uint64_t seed)
 Seed the formula RNG (thread-local engines reseed on next use).
void clearFormulaRandomSeed ()
std::optional< uint64_t > formulaRandomSeed ()
std::mt19937_64 & formulaRng ()

Function Documentation

◆ clearFormulaRandomSeed()

void OpenXLSX::formula::clearFormulaRandomSeed ( )

Clear the optional seed (next RNG construction uses random_device).

◆ coerceArgScalar()

XLCellValue OpenXLSX::formula::coerceArgScalar ( const XLFormulaArg & arg,
bool blankAsZero = true )
nodiscard

Coerce the first scalar of an argument (implicit intersection / top-left).

Returns
Error if the arg is missing/empty (no cells), or coerceToNumber of asScalar().

◆ coerceToNumber()

XLCellValue OpenXLSX::formula::coerceToNumber ( const XLCellValue & v,
bool blankAsZero = true )
nodiscard

Excel-style scalar numeric coercion for math functions and arithmetic.

Error → same error (propagated). Empty → 0 when blankAsZero, else #VALUE!. Integer/Float/Boolean → numeric. Fully-numeric string → number. Else #VALUE!.

Returns
A Float/Integer cell value, or an Error cell value.

◆ errCirc()

XLCellValue OpenXLSX::formula::errCirc ( )
inlinenodiscard

◆ errDiv0()

XLCellValue OpenXLSX::formula::errDiv0 ( )
inlinenodiscard

◆ errNA()

XLCellValue OpenXLSX::formula::errNA ( )
inlinenodiscard

◆ errName()

XLCellValue OpenXLSX::formula::errName ( )
inlinenodiscard

◆ errNum()

XLCellValue OpenXLSX::formula::errNum ( )
inlinenodiscard

◆ errRef()

XLCellValue OpenXLSX::formula::errRef ( )
inlinenodiscard

◆ errValue()

XLCellValue OpenXLSX::formula::errValue ( )
inlinenodiscard

◆ firstError() [1/2]

XLCellValue OpenXLSX::formula::firstError ( const std::vector< XLFormulaArg > & args)
nodiscard

◆ firstError() [2/2]

XLCellValue OpenXLSX::formula::firstError ( const XLFormulaArg & arg)
nodiscard

First error value found in argument cells (Excel left-to-right, top-to-bottom).

Returns
Error value if any, otherwise Empty.

◆ formulaRandomSeed()

std::optional< uint64_t > OpenXLSX::formula::formulaRandomSeed ( )
nodiscard

Currently configured seed, if any.

◆ formulaRng()

std::mt19937_64 & OpenXLSX::formula::formulaRng ( )
nodiscard

Thread-local mt19937_64 used by formula random functions.

◆ isEmpty()

bool OpenXLSX::formula::isEmpty ( const XLCellValue & v)
nodiscard

◆ isError()

bool OpenXLSX::formula::isError ( const XLCellValue & v)
nodiscard

◆ isNumeric()

bool OpenXLSX::formula::isNumeric ( const XLCellValue & v)
nodiscard

◆ makeError()

XLCellValue OpenXLSX::formula::makeError ( std::string_view token)
nodiscard

Build an error XLCellValue with the given Excel error token (e.g. "#VALUE!").

◆ numerics() [1/2]

std::vector< double > OpenXLSX::formula::numerics ( const std::vector< XLFormulaArg > & args)
nodiscard

Flatten numeric values from formula arguments (skips non-numeric cells and errors).

◆ numerics() [2/2]

std::vector< double > OpenXLSX::formula::numerics ( const XLFormulaArg & arg)
nodiscard

◆ numericsOrError() [1/2]

std::vector< double > OpenXLSX::formula::numericsOrError ( const std::vector< XLFormulaArg > & args,
XLCellValue & outError )
nodiscard

Like numerics(), but if any cell is an Error, sets outError and returns {}.

Used by SUM/AVERAGE/MIN/MAX so errors short-circuit instead of being skipped.

◆ numericsOrError() [2/2]

std::vector< double > OpenXLSX::formula::numericsOrError ( const XLFormulaArg & arg,
XLCellValue & outError )
nodiscard

◆ setFormulaRandomSeed()

void OpenXLSX::formula::setFormulaRandomSeed ( uint64_t seed)

Seed the formula RNG (thread-local engines reseed on next use).

When set, RAND/RANDBETWEEN/RANDARRAY produce reproducible sequences within each thread. Call clearFormulaRandomSeed() to restore non-deterministic seeding via std::random_device.

◆ strTrim()

std::string OpenXLSX::formula::strTrim ( std::string s)
nodiscard

◆ toDouble()

double OpenXLSX::formula::toDouble ( const XLCellValue & v)
nodiscard

Convert Integer / Float / Boolean to double; NaN for other types.

◆ toString()

std::string OpenXLSX::formula::toString ( const XLCellValue & v)
nodiscard

Stringify a cell value for text functions; empty for non-displayable types.

◆ tryParseNumericString()

bool OpenXLSX::formula::tryParseNumericString ( std::string_view s,
double & out )
nodiscard

Parse a fully-numeric string (optional leading/trailing space) to double.

Returns
true when the entire trimmed string is a valid number.