truecalc-core
Formula engine with exact Google Sheets semantics — stateless, embeddable, bring your own data model.
484 functions with exact Google Sheets semantics. Ground-truth conformance validated case by case against real Google Sheets — not a spec interpretation. Stateless and embeddable: bring your own data model, no workbook required. Also available as a WebAssembly npm package and as an MCP server for AI assistants.
let result = sheets.evaluate;
// => Value::Number(300.0)
Install
[]
= "0.9"
Or via cargo:
Quick start
use HashMap;
use ;
let engine = sheets;
let mut vars = new;
vars.insert;
vars.insert;
let result = engine.evaluate;
assert_eq!;
Usage
Evaluate a formula
use HashMap;
use ;
let engine = sheets;
let mut vars = new;
vars.insert;
vars.insert;
let result = engine.evaluate;
assert_eq!;
Pattern match on the result
use HashMap;
use ;
let mut vars = new;
vars.insert;
match sheets.evaluate
Validate without evaluating
use Engine;
match sheets.validate
Parse to an AST
use Engine;
let expr = sheets.parse.expect;
// expr is an Expr tree you can walk yourself
Evaluate with a Resolver (workbook integration)
For workbook-backed evaluation where references should be resolved against a
live cell grid, implement the Resolver trait:
use ;
;
let engine = sheets;
assert_eq!;
For a full workbook implementation, see truecalc-workbook.
Engine flavors
The engine flavor controls formula semantics and the date serial system:
| Constructor | Semantics | Date system |
|---|---|---|
Engine::sheets() |
Google Sheets | Day 0 = 1899-12-30, no 1900 leap bug |
Engine::excel() |
Excel | Serial 1 = 1900-01-01, Lotus leap-year bug |
Note: Excel evaluation is not yet implemented.
Engine::excel().evaluate()returns#UNSUPPORTED!.parse()andvalidate()work for both flavors.
Types
Value
| Variant | Description |
|---|---|
Number(f64) |
Finite numeric value (never NaN or infinity) |
Text(String) |
String value |
Bool(bool) |
Boolean value |
Error(ErrorKind) |
Formula error (e.g. #DIV/0!) |
Empty |
Missing/blank cell reference |
Array(Vec<Value>) |
Array of values |
ErrorKind
| Variant | Excel error |
|---|---|
DivByZero |
#DIV/0! |
Value |
#VALUE! |
Ref |
#REF! |
Name |
#NAME? |
Num |
#NUM! |
NA |
#N/A |
Null |
#NULL! |
Available functions
Covers math, logical, text, financial, and statistical categories. For the full list with signatures and descriptions, query the live registry:
use Registry;
let registry = new;
for in registry.list_functions
Migration from 0.6.x
See MIGRATION.md for the full guide.
Summary: The free evaluate() function and Engine::google_sheets() constructor
were deprecated in 0.7.0. Replace them with Engine::sheets().evaluate().
Related crates
truecalc-workbook: full workbook layer with engine-locked workbook, worksheet, cell mutation, and recalc.
Documentation
License
MIT