All Projects → handsontable → Formula Parser

handsontable / Formula Parser

Licence: mit
Javascript Library parsing Excel Formulas and more

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Formula Parser

Excelize
Golang library for reading and writing Microsoft Excel™ (XLSX) files.
Stars: ✭ 10,286 (+1790.81%)
Mutual labels:  excel, formula, spreadsheet
Hyperformula
A complete, open-source Excel-like calculation engine written in TypeScript. Includes 380+ built-in functions. Maintained by the Handsontable team⚡
Stars: ✭ 210 (-61.4%)
Mutual labels:  spreadsheet, parser, formula
fast-formula-parser
Parse and evaluate MS Excel formula in javascript.
Stars: ✭ 341 (-37.32%)
Mutual labels:  formula, excel, spreadsheet
Luckysheet
Luckysheet is an online spreadsheet like excel that is powerful, simple to configure, and completely open source.
Stars: ✭ 9,772 (+1696.32%)
Mutual labels:  excel, spreadsheet, formula
Calx.js
jQuery Calx - a jQuery plugin for creating formula-based calculation form
Stars: ✭ 190 (-65.07%)
Mutual labels:  excel, spreadsheet, formula
spreadsheet
TypeScript/javascript spreadsheet parser, with formulas.
Stars: ✭ 40 (-92.65%)
Mutual labels:  formula, excel, spreadsheet
Reogrid
Fast and powerful .NET spreadsheet component, support data format, freeze, outline, formula calculation, chart, script execution and etc. Compatible with Excel 2007 (.xlsx) format and working on .NET 3.5 (or client profile), WPF and Android platform.
Stars: ✭ 532 (-2.21%)
Mutual labels:  excel, spreadsheet, formula
ExcelFormulaBeautifier
Excel Formula Beautifer,make Excel formulas more easy to read,Excel公式格式化/美化,将Excel公式转为易读的排版
Stars: ✭ 27 (-95.04%)
Mutual labels:  excel, spreadsheet
EPPlus4PHP
an easy-to-use excel library for php project which is compiled with peachpie. NOT FOR THE COMMON PHP PROJECT!
Stars: ✭ 15 (-97.24%)
Mutual labels:  excel, spreadsheet
React Handsontable
React Data Grid with Spreadsheet Look & Feel. Official React wrapper for Handsontable.
Stars: ✭ 511 (-6.07%)
Mutual labels:  excel, spreadsheet
Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (-11.58%)
Mutual labels:  excel, parser
excel validator
Python script to validate data in Excel files
Stars: ✭ 14 (-97.43%)
Mutual labels:  excel, spreadsheet
XToolset
Typed import, and export XLSX spreadsheet to JS / TS. Template-based create, render, and export data into excel files.
Stars: ✭ 110 (-79.78%)
Mutual labels:  excel, spreadsheet
rowy
Open-source Airtable-like experience for your database (Firestore) with GCP's scalability. Build any automation or cloud functions for your product. ⚡️✨
Stars: ✭ 2,676 (+391.91%)
Mutual labels:  excel, spreadsheet
OpenWebSheet
OpenSource Web based spreadsheet
Stars: ✭ 30 (-94.49%)
Mutual labels:  formula, spreadsheet
Unioffice
Pure go library for creating and processing Office Word (.docx), Excel (.xlsx) and Powerpoint (.pptx) documents
Stars: ✭ 3,111 (+471.88%)
Mutual labels:  excel, spreadsheet
fxl.js
ƛ fxl.js is a data-oriented JavaScript spreadsheet library. It provides a way to build spreadsheets using modular, lego-like blocks.
Stars: ✭ 27 (-95.04%)
Mutual labels:  excel, spreadsheet
jupyterlab-spreadsheet-editor
JupyterLab spreadsheet editor for tabular data (e.g. csv, tsv)
Stars: ✭ 72 (-86.76%)
Mutual labels:  excel, spreadsheet
Reactgrid
Add spreadsheet-like behavior to your React app
Stars: ✭ 289 (-46.87%)
Mutual labels:  excel, spreadsheet
React Spreadsheet
Simple, customizable yet performant spreadsheet for React
Stars: ✭ 393 (-27.76%)
Mutual labels:  excel, spreadsheet

Formula Parser Build Status Test Coverage hot-formula-parser

Library provides a Parser class that evaluates excel and mathematical formulas.


Install

A recommended way to install Formula Parser is through NPM using the following command:

$ npm install hot-formula-parser --save

Node.js:

var FormulaParser = require('hot-formula-parser').Parser;
var parser = new FormulaParser();

parser.parse('SUM(1, 6, 7)'); // It returns `Object {error: null, result: 14}`

Browser:

<script src="/node_modules/hot-formula-parser/dist/formula-parser.min.js"></script>
<script>
var parser = new formulaParser.Parser();

parser.parse('SUM(1, 6, 7)'); // It returns `Object {error: null, result: 14}`
</script>

Features

It supports:

  • Any numbers, negative and positive as float or integer;
  • Arithmetic operations like +, -, /, *, %, ^;
  • Logical operations like AND(), OR(), NOT(), XOR();
  • Comparison operations like =, >, >=, <, <=, <>;
  • All JavaScript Math constants like PI(), E(), LN10(), LN2(), LOG10E(), LOG2E(), SQRT1_2(), SQRT2();
  • String operations like & (concatenation eq. parser.parse('-(2&5)'); will return -25);
  • All excel formulas defined in formula.js;
  • Relative and absolute cell coordinates like A1, $A1, A$1, $A$1;
  • Build-in variables like TRUE, FALSE, NULL
  • Custom variables;
  • Custom functions/formulas;
  • Node and Browser environment.

API (methods)

var parser = new formulaParser.Parser();

.parse(expression)

Parses and evaluates provided expression. It always returns an object with result and error properties. result property always keep evaluated value. If error occurs error property will be set as:

  • #ERROR! General error;
  • #DIV/0! Divide by zero error;
  • #NAME? Not recognised function name or variable name;
  • #N/A Indicates that a value is not available to a formula;
  • #NUM! Occurs when formula encounters an invalid number;
  • #VALUE! Occurs when one of formula arguments is of the wrong type.
parser.parse('(1 + 5 + (5 * 10)) / 10'); // returns `Object {error: null, result: 5.6}`
parser.parse('SUM(MY_VAR)'); // returns `Object {error: "#NAME?", result: null}`
parser.parse('1;;1'); // returns `Object {error: "#ERROR!", result: null}`

.setVariable(name, value)

Set predefined variable name which can be visible while parsing formula expression.

parser.setVariable('MY_VARIABLE', 5);
parser.setVariable('fooBar', 10);

parser.parse('(1 + MY_VARIABLE + (5 * fooBar)) / fooBar'); // returns `5.6`

.getVariable(name)

Get variable name.

parser.setVariable('fooBar', 10);

parser.getVariable('fooBar'); // returns `10`

.setFunction(name, fn)

Set custom function which can be visible while parsing formula expression.

parser.setFunction('ADD_5', function(params) {
  return params[0] + 5;
});
parser.setFunction('GET_LETTER', function(params) {
  var string = params[0];
  var index = params[1] - 1;

  return string.charAt(index);
});

parser.parse('SUM(4, ADD_5(1))'); // returns `10`
parser.parse('GET_LETTER("Some string", 3)'); // returns `m`

.getFunction(name)

Get custom function.

parser.setFunction('ADD_5', function(params) {
  return params[0] + 5;
});

parser.getFunction('ADD_5')([1]); // returns `6`

.SUPPORTED_FORMULAS

List of all supported formulas function.

require('hot-formula-parser').SUPPORTED_FORMULAS; // An array of formula names

API (hooks)

'callVariable' (name, done)

Fired while retrieving variable. If variable was defined earlier using setVariable you can overwrite it by this hook.

parser.on('callVariable', function(name, done) {
  if (name === 'foo') {
    done(Math.PI / 2);
  }
});

parser.parse('SUM(SIN(foo), COS(foo))'); // returns `1`

'callFunction' (name, params, done)

Fired while calling function. If function was defined earlier using setFunction you can overwrite it's result by this hook. You can also use this to override result of build-in formulas.

parser.on('callFunction', function(name, params, done) {
  if (name === 'ADD_5') {
    done(params[0] + 5);
  }
});

parser.parse('ADD_5(3)'); // returns `8`

'callCellValue' (cellCoord, done)

Fired while retrieving cell value by its label (eq: B3, B$3, B$3, $B$3).

parser.on('callCellValue', function(cellCoord, done) {
  // using label
  if (cellCoord.label === 'B$6') {
    done('hello');
  }
  // or using indexes
  if (cellCoord.row.index === 5 && cellCoord.row.isAbsolute && cellCoord.column.index === 1 && !cellCoord.column.isAbsolute) {
    done('hello');
  }

  if (cellCoord.label === 'C6') {
    done(0.75);
  }
});

parser.parse('B$6'); // returns `"hello"`
parser.parse('B$6&" world"'); // returns `"hello world"`
parser.parse('FISHER(C6)'); // returns `0.9729550745276566`

'callRangeValue' (startCellCoord, endCellCoord, done)

Fired while retrieving cells range value (eq: A1:B3, $A1:B$3, A$1:B$3, $A$1:$B$3).

parser.on('callRangeValue', function(startCellCoord, endCellCoord, done) {
  var data = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, 13, 14, 15],
    [16, 17, 18, 19, 20],
  ];
  var fragment = [];

  for (var row = startCellCoord.row.index; row <= endCellCoord.row.index; row++) {
    var rowData = data[row];
    var colFragment = [];

    for (var col = startCellCoord.column.index; col <= endCellCoord.column.index; col++) {
      colFragment.push(rowData[col]);
    }
    fragment.push(colFragment);
  }

  if (fragment) {
    done(fragment);
  }
});

parser.parse('JOIN(A1:E2)'); // returns `"1,2,3,4,5,6,7,8,9,10"`
parser.parse('COLUMNS(A1:E2)'); // returns `5`
parser.parse('ROWS(A1:E2)'); // returns `2`
parser.parse('COUNT(A1:E2)'); // returns `10`
parser.parse('COUNTIF(A1:E2, ">5")'); // returns `5`

Want to help?

Please see CONTRIBUTING.md.

Changelog

To see the list of recent changes, see Releases section.

License

The MIT License (see the LICENSE file for the full text).

Contact

You can contact us at [email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].