ReoGrid ReoGrid Web

Formula Engine

ReoGrid Web includes an Excel-compatible formula engine. It features an AST parser, evaluator, and dependency graph for real-time recalculation.

The Lite edition supports arithmetic operators and cell references. All 32+ built-in functions require the Pro edition.

Live Demo

Basic Usage

Cell values starting with = are interpreted as formulas.

const ws = grid.worksheet

// Arithmetic operations
ws.cell('C1').value = '=A1+B1'
ws.cell('C2').value = '=A2*B2'

// Function calls
ws.cell('C3').value = '=SUM(A1:A10)'
ws.cell('C4').value = '=IF(A1>100,"High","Low")'

Cell References

FormatDescriptionExample
Relative referenceRow and column indices shiftA1, B2
Absolute referenceFixed with $$A$1, A$1, $A1
Range referenceRange specified with colonA1:B10

Built-in Functions

Math Functions

FunctionSyntaxDescription
SUMSUM(range)Sum
AVERAGEAVERAGE(range)Average
MINMIN(range)Minimum value
MAXMAX(range)Maximum value
COUNTCOUNT(range)Count of numeric cells
COUNTACOUNTA(range)Count of non-empty cells
COUNTIFCOUNTIF(range, criteria)Count of cells matching criteria
ABSABS(number)Absolute value
SQRTSQRT(number)Square root
POWERPOWER(base, exp)Exponentiation
MODMOD(number, divisor)Remainder
ROUNDROUND(number, digits)Round
PRODUCTPRODUCT(range)Product

Logical Functions

FunctionSyntaxDescription
IFIF(condition, true_val, false_val)Conditional branching
ANDAND(cond1, cond2, ...)TRUE if all are true
OROR(cond1, cond2, ...)TRUE if any is true
NOTNOT(condition)Logical negation

String Functions

FunctionSyntaxDescription
CONCATENATECONCATENATE(str1, str2, ...)String concatenation
LENLEN(text)Character count
UPPERUPPER(text)Convert to uppercase
LOWERLOWER(text)Convert to lowercase
TRIMTRIM(text)Remove leading/trailing whitespace
FINDFIND(search, text, start?)Find character position
REPLACEREPLACE(text, start, count, new)Replace characters
SUBSTRINGSUBSTRING(text, start, length?)Substring

Lookup Functions

FunctionSyntaxDescription
VLOOKUPVLOOKUP(value, range, col_index, approx?)Vertical lookup
HLOOKUPHLOOKUP(value, range, row_index, approx?)Horizontal lookup

Date Functions

FunctionSyntaxDescription
TODAYTODAY()Today’s date (serial value)
NOWNOW()Current date and time (serial value)

Type Checking Functions

FunctionSyntaxDescription
ISNUMBERISNUMBER(value)TRUE if numeric
ISTEXTISTEXT(value)TRUE if text
ISBLANKISBLANK(cell)TRUE if empty
ISERRORISERROR(value)TRUE if error

Automatic Dependency Tracking

Dependencies between formulas are tracked automatically. When a cell value changes, all formulas that reference that cell are automatically recalculated.

ws.cell('A1').value = '10'
ws.cell('B1').value = '20'
ws.cell('C1').value = '=A1+B1'  // -> 30

// Changing A1 automatically recalculates C1
ws.cell('A1').value = '50'      // C1 -> 70

You can rebuild formula dependencies after bulk data changes:

ws.rebuildFormulas()

Example: Invoice Calculations

const ws = grid.worksheet

// Headers
ws.cell('A1').value = 'Item'
ws.cell('B1').value = 'Quantity'
ws.cell('C1').value = 'Unit Price'
ws.cell('D1').value = 'Amount'

// Data rows
ws.cell('A2').value = 'Widget'
ws.cell('B2').value = '10'
ws.cell('C2').value = '500'
ws.cell('D2').value = '=B2*C2'   // -> 5000

ws.cell('A3').value = 'Gadget'
ws.cell('B3').value = '5'
ws.cell('C3').value = '1200'
ws.cell('D3').value = '=B3*C3'   // -> 6000

// Subtotal
ws.cell('D5').value = '=SUM(D2:D3)'      // -> 11000

// Tax
ws.cell('D6').value = '=ROUND(D5*0.1,0)' // -> 1100

// Total
ws.cell('D7').value = '=D5+D6'           // -> 12100

Edition Comparison

FeatureLite (Free)Pro (Paid)
Arithmetic operators (+, -, *, /)YesYes
Cell & range referencesYesYes
Dependency graphYesYes
Built-in functions (32+)Yes