|
OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
|
Sheet- or workbook-scoped formula calculation engine (Phase C). More...
#include <XLCalculationEngine.hpp>
Public Types | |
| using | FormulaMap = std::unordered_map<std::string, std::string> |
| "A1" or "Sheet2!A1" -> formula | |
| using | ValueMap = std::unordered_map<std::string, XLCellValue> |
Public Member Functions | |
| XLCalculationEngine (XLWorksheet &worksheet, XLCalculationOptions options={}) | |
| XLCalculationEngine (XLDocument &document, XLCalculationOptions options={}) | |
| All worksheets in a document (multi-sheet graph; keys always carry sheet name). | |
| XLCalculationEngine (FormulaMap formulas, ValueMap values, XLCalculationOptions options={}, std::string defaultSheet={}) | |
| In-memory model for unit tests. | |
| ~XLCalculationEngine () | |
| XLCalculationEngine (const XLCalculationEngine &)=delete | |
| XLCalculationEngine & | operator= (const XLCalculationEngine &)=delete |
| XLCalculationEngine (XLCalculationEngine &&)=delete | |
| XLCalculationEngine & | operator= (XLCalculationEngine &&)=delete |
| const XLCalculationOptions & | options () const noexcept |
| void | setOptions (XLCalculationOptions options) |
| bool | isMultiSheet () const noexcept |
| void | rebuild () |
| size_t | formulaCount () const noexcept |
| size_t | dirtyCount () const noexcept |
| std::vector< XLCellKey > | dependencies (const XLCellKey &cell) const |
| std::vector< XLCellKey > | dependencies (std::string_view a1) const |
| std::vector< XLCellKey > | dependents (const XLCellKey &cell) const |
| std::vector< XLCellKey > | dependents (std::string_view a1) const |
| XLCellValue | calcCellValue (const XLCellKey &cell) |
| Evaluate one cell, recursively calculating precedent formula cells. | |
| XLCellValue | calcCellValue (std::string_view a1) |
| XLCalcStatus | lastStatus () const noexcept |
| size_t | recalculate () |
| Recalculate only dirty formula cells. | |
| size_t | recalculateAll () |
| Mark all formulas dirty, then recalculate. | |
| void | markDirty (const XLCellKey &cell, bool propagate) |
| Mark a cell dirty; with propagateDirty, also all transitive dependents. | |
| void | markDirty (const XLCellKey &cell) |
| void | markDirty (std::string_view a1, bool propagate) |
| void | markDirty (std::string_view a1) |
| void | markAllDirty () |
| void | setInputValue (const XLCellKey &cell, const XLCellValue &value) |
| Update an input value and dirty all dependent formulas. | |
| void | setInputValue (std::string_view a1, const XLCellValue &value) |
| void | notifyChanged (const XLCellKey &cell) |
| Notify that a cell changed externally (same as markDirty with propagation). | |
| void | notifyChanged (std::string_view a1) |
| void | clearCache () |
| void | setDefinedNames (std::unordered_map< std::string, std::string > names) |
| Inject defined names for map-mode engines (name → refersTo formula, e.g. "Sales" → "=$B$2"). | |
| void | reloadDefinedNames () |
| Reload defined names from the bound workbook (sheet/document engines). | |
| bool | updateFormulaCell (const XLCellKey &cell) |
| Locally update one formula cell in the graph without full rebuild. | |
| bool | updateFormulaCell (std::string_view a1) |
Static Public Member Functions | |
| static std::vector< XLCellKey > | extractDependencies (std::string_view formula, std::string_view defaultSheet={}, size_t maxExpanded=4096, bool forceDefaultSheet=false, const std::unordered_map< std::string, std::string > *definedNames=nullptr) |
| Extract cell/range dependencies from a formula string (public for tests). | |
Sheet- or workbook-scoped formula calculation engine (Phase C).
Builds a dependency graph over formula cells, evaluates with caching and circular detection, propagates dirty flags to dependents, and can recalculate only dirty cells or the full graph.
| using OpenXLSX::XLCalculationEngine::FormulaMap = std::unordered_map<std::string, std::string> |
"A1" or "Sheet2!A1" -> formula
| using OpenXLSX::XLCalculationEngine::ValueMap = std::unordered_map<std::string, XLCellValue> |
|
explicit |
Single worksheet (sheet-local graph; empty sheet keys).
|
explicit |
All worksheets in a document (multi-sheet graph; keys always carry sheet name).
| OpenXLSX::XLCalculationEngine::XLCalculationEngine | ( | FormulaMap | formulas, |
| ValueMap | values, | ||
| XLCalculationOptions | options = {}, | ||
| std::string | defaultSheet = {} ) |
In-memory model for unit tests.
| formulas | Map of address -> formula. Use "Sheet!A1" for multi-sheet graphs. |
| values | Constant / seed values (same key conventions). |
| defaultSheet | Optional default sheet name for unqualified addresses. |
| OpenXLSX::XLCalculationEngine::~XLCalculationEngine | ( | ) |
|
delete |
|
delete |
|
nodiscard |
Evaluate one cell, recursively calculating precedent formula cells.
|
nodiscard |
| void OpenXLSX::XLCalculationEngine::clearCache | ( | ) |
Clear evaluation caches and visit colours (keeps formula text / deps).
|
nodiscard |
Direct precedents (cells this formula reads).
|
nodiscard |
|
nodiscard |
Direct dependents (formulas that read this cell). Includes non-formula seeds as keys.
|
nodiscard |
|
nodiscardnoexcept |
Number of formula cells currently marked dirty.
|
staticnodiscard |
Extract cell/range dependencies from a formula string (public for tests).
| forceDefaultSheet | When true, unqualified refs get sheet=defaultSheet. |
| definedNames | Optional uppercase-name → refersTo map for expanding named ranges. |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
| void OpenXLSX::XLCalculationEngine::markAllDirty | ( | ) |
| void OpenXLSX::XLCalculationEngine::markDirty | ( | const XLCellKey & | cell | ) |
| void OpenXLSX::XLCalculationEngine::markDirty | ( | const XLCellKey & | cell, |
| bool | propagate ) |
Mark a cell dirty; with propagateDirty, also all transitive dependents.
| cell | Any cell (input seed or formula). |
| propagate | Override options.propagateDirty when set. |
| void OpenXLSX::XLCalculationEngine::markDirty | ( | std::string_view | a1 | ) |
| void OpenXLSX::XLCalculationEngine::markDirty | ( | std::string_view | a1, |
| bool | propagate ) |
| void OpenXLSX::XLCalculationEngine::notifyChanged | ( | const XLCellKey & | cell | ) |
Notify that a cell changed externally (same as markDirty with propagation).
| void OpenXLSX::XLCalculationEngine::notifyChanged | ( | std::string_view | a1 | ) |
|
delete |
|
delete |
|
inlinenodiscardnoexcept |
| void OpenXLSX::XLCalculationEngine::rebuild | ( | ) |
(Re)scan formula cells and rebuild dependency + reverse-dependency graphs.
| size_t OpenXLSX::XLCalculationEngine::recalculate | ( | ) |
Recalculate only dirty formula cells.
| size_t OpenXLSX::XLCalculationEngine::recalculateAll | ( | ) |
Mark all formulas dirty, then recalculate.
| void OpenXLSX::XLCalculationEngine::reloadDefinedNames | ( | ) |
Reload defined names from the bound workbook (sheet/document engines).
| void OpenXLSX::XLCalculationEngine::setDefinedNames | ( | std::unordered_map< std::string, std::string > | names | ) |
Inject defined names for map-mode engines (name → refersTo formula, e.g. "Sales" → "=$B$2").
Names are matched case-insensitively. Call before rebuild() or rebuild after set.
| void OpenXLSX::XLCalculationEngine::setInputValue | ( | const XLCellKey & | cell, |
| const XLCellValue & | value ) |
Update an input value and dirty all dependent formulas.
Writes to the value map or worksheet cell, then markDirty(propagate).
| void OpenXLSX::XLCalculationEngine::setInputValue | ( | std::string_view | a1, |
| const XLCellValue & | value ) |
|
inline |
| bool OpenXLSX::XLCalculationEngine::updateFormulaCell | ( | const XLCellKey & | cell | ) |
Locally update one formula cell in the graph without full rebuild.
Reads the live formula from the worksheet/map; removes the node if no formula.
| bool OpenXLSX::XLCalculationEngine::updateFormulaCell | ( | std::string_view | a1 | ) |