SpreadsheetEvaluator.h header
#include <ew/core/SpreadsheetEvaluator.h>
Namespace ew::core
Functions
QString ew::core::evaluatedValue(const Spreadsheet &sheet, int row, int column)
Evaluates the cell at (row, column) of sheet to the text it should display.
A cell whose text is not a formula (does not begin with '=') displays that text verbatim. A formula ("=<expression>") is parsed and computed over the sheet's cells. A computed value is either a number or text. It supports:
- decimal numbers, double-quoted text literals ("hello", with "" for an embedded quote), and the arithmetic operators + - * / with the usual precedence, parentheses, and unary minus;
- the comparison operators = <> < > <= >= (which yield 1 for true and 0 for false) at the lowest precedence, so IF(...) conditions read naturally; two numbers compare numerically, otherwise operands compare as text;
- A1-style cell references (resolved recursively) – a single reference reads the cell's number or text – and A1:B2 ranges (empty and text cells in a range are skipped); the column and the row may each be pinned with a '$' ($A$1, $A1, A$1), which reads as the same cell as the unpinned form (a pin governs only which cell a formula points at once it is copied elsewhere);
- the aggregate functions SUM, PRODUCT, AVERAGE, MIN, MAX, and COUNT over comma-separated arguments and ranges;
- the math functions ABS, INT, SQRT, POWER(base, exp), MOD(a, b), and ROUND(value[, digits]);
- the logical functions IF(condition, then, else) (whose branches may be text), AND, OR, NOT; and
- the text functions CONCAT(...), LEFT(text, n), RIGHT(text, n), MID(text, start, length), LEN(text), UPPER(text), LOWER(text), and TRIM(text). A numeric result is formatted for display and text is returned as-is, or one of the error tokens "#REF!" (bad reference), "#CIRC!" (a reference cycle), "#DIV/0!" (division by zero), or "#ERR!" (a malformed formula, arithmetic on non-numeric text, or a function given the wrong number of arguments) is returned.