Convert Figma logo to code with AI

sutoiku logoformula.js

JavaScript implementation of most Microsoft Excel formula functions

2,151
294
2,151
28

Top Related Projects

35,733

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.

6,953

Jspreadsheet is a lightweight JavaScript data grid component for creating interactive data grids with advanced spreadsheet controls.

14,513

Excel Workbook Manager

An arbitrary-precision Decimal type for JavaScript

Quick Overview

Formula.js is a JavaScript library that implements Excel formula functions in JavaScript. It aims to provide a comprehensive set of Excel-compatible functions for use in web applications, making it easier to port Excel-based calculations to the web or create web-based spreadsheet applications.

Pros

  • Extensive coverage of Excel functions, including financial, statistical, and mathematical operations
  • Compatibility with Excel formulas, allowing for easier migration of Excel-based calculations to web applications
  • Active development and maintenance, with regular updates and bug fixes
  • Well-documented API with clear examples for each function

Cons

  • Performance may be slower compared to native Excel calculations for complex or large-scale operations
  • Some advanced Excel features or newer functions may not be fully implemented
  • Dependency on external libraries for certain functions (e.g., jstat for statistical operations)
  • Potential discrepancies in edge cases or precision compared to Excel's implementation

Code Examples

  1. Basic arithmetic operation:
const result = formulajs.SUM(1, 2, 3, 4, 5);
console.log(result); // Output: 15
  1. Financial function:
const presentValue = formulajs.PV(0.08, 10, -1000, 0, 0);
console.log(presentValue); // Output: 6710.08
  1. Statistical function:
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const average = formulajs.AVERAGE(data);
console.log(average); // Output: 5.5
  1. Text manipulation:
const text = "Hello, World!";
const extractedText = formulajs.LEFT(text, 5);
console.log(extractedText); // Output: "Hello"

Getting Started

To use Formula.js in your project, follow these steps:

  1. Install the library using npm:
npm install @formulajs/formulajs
  1. Import the library in your JavaScript file:
import * as formulajs from '@formulajs/formulajs';
  1. Start using the functions in your code:
const result = formulajs.SUM(1, 2, 3);
console.log(result); // Output: 6

Competitor Comparisons

35,733

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs

Pros of SheetJS

  • Broader functionality: Handles reading, writing, and manipulating spreadsheet files in various formats (XLSX, CSV, etc.)
  • Larger community and more frequent updates
  • Extensive documentation and examples

Cons of SheetJS

  • Larger file size and potentially higher resource usage
  • Steeper learning curve due to more complex API
  • Some features require a commercial license

Code Comparison

formula.js:

var result = Formula.SUM([1, 2, 3, 4]);
console.log(result); // Output: 10

SheetJS:

var workbook = XLSX.utils.book_new();
var worksheet = XLSX.utils.aoa_to_sheet([[1, 2, 3, 4]]);
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
var sum = XLSX.utils.sheet_get_array(worksheet)[0].reduce((a, b) => a + b, 0);
console.log(sum); // Output: 10

Summary

formula.js focuses specifically on implementing Excel formula functions in JavaScript, making it lightweight and easy to use for formula calculations. SheetJS, on the other hand, offers a comprehensive solution for working with spreadsheet files, including reading, writing, and manipulation. While SheetJS provides more features, it comes with a larger footprint and potentially higher complexity. The choice between the two depends on the specific requirements of your project.

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.

Pros of HyperFormula

  • More comprehensive formula support, including advanced Excel-compatible functions
  • Better performance for large datasets and complex calculations
  • Actively maintained with regular updates and improvements

Cons of HyperFormula

  • Larger package size, which may impact load times for web applications
  • Steeper learning curve due to more complex API and configuration options
  • Commercial licensing for certain use cases, unlike Formula.js which is MIT licensed

Code Comparison

HyperFormula:

import { HyperFormula } from 'hyperformula';

const hf = HyperFormula.buildEmpty({
  licenseKey: 'gpl-v3'
});

const sheetName = hf.addSheet('Sheet1');
hf.setCellContents({ sheet: sheetName, row: 0, col: 0 }, '=SUM(1, 2, 3)');
const result = hf.getCellValue({ sheet: sheetName, row: 0, col: 0 });

Formula.js:

import { sum } from 'formula.js';

const result = sum(1, 2, 3);

HyperFormula offers a more Excel-like experience with sheet management and cell references, while Formula.js provides a simpler function-based approach. HyperFormula is better suited for complex spreadsheet-like applications, whereas Formula.js is ideal for simpler calculations in JavaScript projects.

6,953

Jspreadsheet is a lightweight JavaScript data grid component for creating interactive data grids with advanced spreadsheet controls.

Pros of jspreadsheet/ce

  • Full-featured spreadsheet component with UI and interactivity
  • Supports plugins and extensions for added functionality
  • Includes data validation, sorting, and filtering capabilities

Cons of jspreadsheet/ce

  • Larger file size and more complex implementation
  • May be overkill for projects only needing formula calculations
  • Steeper learning curve for basic spreadsheet operations

Code Comparison

formula.js:

var result = Formula.SUM([1, 2, 3, 4]);
console.log(result); // Output: 10

jspreadsheet/ce:

jspreadsheet(document.getElementById('spreadsheet'), {
    data: [['=SUM(A1:A4)']],
    columns: [{ type: 'numeric' }]
});

Summary

formula.js focuses solely on providing Excel-like formula calculations, making it lightweight and easy to integrate for specific formula needs. jspreadsheet/ce offers a complete spreadsheet solution with UI components, making it more suitable for projects requiring a full spreadsheet experience. While formula.js is more straightforward for basic calculations, jspreadsheet/ce provides a richer set of features at the cost of increased complexity and file size.

14,513

Excel Workbook Manager

Pros of ExcelJS

  • Comprehensive Excel file manipulation (read, write, edit)
  • Supports complex formatting and styling of spreadsheets
  • Active development and large community support

Cons of ExcelJS

  • Larger package size and potentially higher resource usage
  • Steeper learning curve for basic Excel formula operations
  • May be overkill for simple spreadsheet calculations

Code Comparison

ExcelJS (creating a workbook and adding a formula):

const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');
worksheet.getCell('A1').value = { formula: 'SUM(B1:B5)' };

Formula.js (performing a calculation):

const result = formulajs.SUM([1, 2, 3, 4, 5]);

Summary

ExcelJS is a comprehensive library for working with Excel files, offering extensive features for file manipulation, formatting, and complex operations. It's ideal for projects requiring full Excel functionality.

Formula.js focuses specifically on implementing Excel formulas in JavaScript, making it lighter and more straightforward for basic calculations. It's better suited for projects that only need to perform Excel-like calculations without file handling.

Choose ExcelJS for complete Excel file operations and Formula.js for simpler, formula-focused tasks.

An arbitrary-precision Decimal type for JavaScript

Pros of decimal.js

  • Specialized for arbitrary-precision decimal and binary arithmetic
  • Extensive documentation and API reference
  • Supports advanced mathematical operations like exponential and logarithmic functions

Cons of decimal.js

  • Focused solely on numerical operations, lacking spreadsheet-like functions
  • May have a steeper learning curve for users familiar with Excel-style formulas
  • Potentially slower for simple calculations due to its precision-focused design

Code Comparison

decimal.js:

const Decimal = require('decimal.js');
let x = new Decimal(10);
let y = new Decimal(3);
let result = x.dividedBy(y);
console.log(result.toString()); // Outputs: 3.3333333333333333333333333333333333

formula.js:

const formulajs = require('formula.js');
let x = 10;
let y = 3;
let result = formulajs.DIVIDE(x, y);
console.log(result); // Outputs: 3.3333333333333335

Summary

decimal.js excels in high-precision arithmetic and complex mathematical operations, making it ideal for financial calculations or scientific computing. formula.js, on the other hand, provides a more familiar interface for users accustomed to spreadsheet functions, offering a wider range of non-mathematical operations. The choice between the two depends on the specific requirements of the project, with decimal.js being more suitable for precision-critical applications and formula.js for general-purpose spreadsheet-like functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

formula.js

DEPRECATED: this repository has been deprecated. The project continues at formulajs/formulajs. Documentation can be found here

JavaScript implementation of most Microsoft Excel formula functions

USAGE

Formulas depends on the following Open source Javascript libraries: Numeric, NumeralJs and jStats.

Include them as follow to use formula.js in your browser:

<!-- Numeric -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script>
<!-- Numeral.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>
<!-- jStat -->
<script src="https://cdn.jsdelivr.net/jstat/latest/jstat.min.js"></script>

<!-- Finally add formula.js -->
<script src="local-formula-path/formula.js"></script>

LICENSE

formula.js is freely distributable under the terms of the MIT license. Copyright (c) 2014 Sutoiku, Inc.

NPM DownloadsLast 30 Days