# xlsx-syntax

> Parse formulas in XLSX syntax and generate a result

Latest version **0.6.0** (published 2025-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install xlsx-syntax
pnpm add xlsx-syntax
yarn add xlsx-syntax
bun add xlsx-syntax
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2025-11-18 |
| First published | 2022-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jonathan Keebler |
| Maintainers | keebler |
| Keywords | xlsx, parse, formula |

## Links

- npm: https://www.npmjs.com/package/xlsx-syntax
- Repository: https://github.com/baselinecapital/xlsx-syntax
- Homepage: https://github.com/baselinecapital/xlsx-syntax#readme
- Issues: https://github.com/baselinecapital/xlsx-syntax/issues
- npm.io page: https://npm.io/package/xlsx-syntax

## Dependencies (3)

- [mustache](https://npm.io/package/mustache.md) ^4.2.0
- [@formulajs/formulajs](https://npm.io/package/@formulajs/formulajs.md) ^4.5.4
- [@baselinelending/xlsx-calc](https://npm.io/package/@baselinelending/xlsx-calc.md) ^0.9.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2025-11-18
- 0.5.1 — 2024-09-24
- 0.5.0 — 2024-09-24
- 0.4.1 — 2023-02-01
- 0.4.0 — 2022-12-16
- 0.3.2 — 2022-12-08
- 0.3.1 — 2022-12-08
- 0.3.0 — 2022-12-07
- 0.2.5 — 2022-12-07
- 0.2.4 — 2022-12-07
- 0.2.3 — 2022-10-21
- 0.2.2 — 2022-10-20
- 0.2.1 — 2022-10-19
- 0.2.0 — 2022-10-17
- 0.1.2 — 2022-10-17
- … 2 more at https://npm.io/package/xlsx-syntax/versions

## README

# XLSX Formula Parser

Parses XLSX-style formulas with variable substitution, and produces a result. Supports the formulas [in the xlsx-calc project](https://github.com/fabiooshiro/xlsx-calc/blob/master/src/formulas.js#L6). The formula is written using [mustache](https://github.com/janl/mustache.js/) syntax, including custom tags. Any array variables produce a range within the formula e.g. `SUM({{array}})` with variable `array:[1,2,3]` is equivalent to `SUM(A1:A3)` where the rows are `1,2,3` respectively.

## Installation

```bash
npm install xlsx-syntax
```

## Usage

```js
const { calculate } = require("xlsx-syntax");

// Calculate the result of the function
calculate(formula, variables, [customTags], [suppress_errors /* true */]);

// Parse out any variables that should be passed
parse(formula, [customTags]);
```

## Example (Variables from key-values)

```js
const { calculate, parse } = require("xlsx-syntax");
calculate("1+{{a}}", { a: 2 });
// 3

calculate("1+SUM({{a}})", { a: [1, 2, 3] });
// 7

calculate("1+SUM({{a}})", {
	a: () => {
		// Do something
		return [1, 2, 3];
	},
});
// 7

calculate("1/0");
// undefined

calculate("1/0", undefined, undefined, false);
// Throw error: #DIV/0!

// Custom tags
calculate("1+${a}", { a: 2 }, ["${", "}"]);
// 3

parse("1+{{a}}/{{b}}");
// ["a", "b"]
```

## Example (Variables from function)

```js
const { calculate, parse } = require("xlsx-syntax");
calculate("1+{{a}}", name => {
	switch (name) {
		case "a":
			return 2;
	}
});
// 3

calculate("1+SUM({{a}})", name => {
	switch (name) {
		case "a":
			return [1, 2, 3];
	}
});
// 7
```

## Special Thanks

Special thanks to the team who made [xlsx-calc](https://github.com/fabiooshiro/xlsx-calc) who made the underlying formula parsing for this library.

## MIT License

Copyright 2024, Baseline Financial Technologies Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
_Source: https://npm.io/package/xlsx-syntax · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
