How to use the Excel Formula to JavaScript
- Paste an Excel or Google Sheets formula, or pick one from Examples.
- Choose the target language — the page starts with JavaScript, and you can switch at any time.
- Rename the detected cell references to meaningful variable names, for example
B2→price. - Choose a full function or the bare expression, then copy or download the code. Helper functions are added automatically when a formula needs them.
Why convert Excel formulas to JavaScript?
Business logic often starts life in a spreadsheet: a pricing model, a commission table, an eligibility check. When that logic moves into a web app, a Node.js API or a Google Apps Script, every formula has to be rewritten by hand — and subtle differences between Excel and JavaScript cause bugs that only show up with real data. This converter parses the formula exactly as Excel does and writes equivalent JavaScript.
=IF(AND(B2>=18, C2="yes"), "Eligible", "Not eligible")
function calculate(B2, C2) {
return B2 >= 18 && C2 === 'yes' ? 'Eligible' : 'Not eligible';
}
How Excel functions map to JavaScript
| Excel | JavaScript |
|---|---|
IF(c, a, b) | c ? a : b |
IFS / SWITCH | nested ternaries |
AND, OR, NOT | &&, ||, ! |
= and <> | === and !== |
a & b | String(a) + b |
a ^ b | a ** b |
SUM(A2:A10) | A2_A10.reduce(…) |
ROUND(x, 2) | round() helper (half away from zero) |
MOD(a, b) | mod() helper |
SUMIFS / COUNTIF… | sumIfs(), countIf() helpers |
VLOOKUP / XLOOKUP | vlookup(), xlookup() helpers |
IFERROR(x, y) | ifError(() => x, y) |
LEFT / MID / LEN | .slice(), .substr(), .length |
TODAY() / NOW() | new Date() |
Differences that cause bugs
- Operator precedence. In Excel
=-2^2is 4 because negation binds tighter than^. JavaScript does not even allow-2 ** 2. The converter always adds the parentheses Excel implies:(-2) ** 2. - Rounding. Excel rounds halves away from zero;
Math.round(-2.5)returns −2 and(1.005).toFixed(2)gives "1.00". The generatedround()helper matches Excel. - Remainders.
MOD(-7, 3)is 2 in Excel but-7 % 3is −1 in JavaScript, so amod()helper is used. - Text comparison. Excel's
=ignores case for text;===does not. Lookups and criteria helpers compare case-insensitively like Excel. - Concatenation.
&always produces text, while+adds numbers. The converter wraps the first operand inString()soA1 & B1never turns into a sum. - Errors. Division by zero returns
Infinityinstead of throwing, soifError()checks for non-finite results as well as exceptions.
Ranges, lookups and criteria
A single-column or single-row range such as A2:A100 becomes an array parameter; a multi-column range such as A2:C500 becomes an array of rows, which is the shape vlookup() expects. Criteria strings work like in Excel: ">=1000", "<>closed" and wildcards such as "*@example.com".
Supported functions: IF, IFS, SWITCH, AND, OR, NOT, XOR, IFERROR, IFNA, ISBLANK, ISNUMBER, ISTEXT, SUM, AVERAGE, MIN, MAX, COUNT, COUNTA, COUNTBLANK, PRODUCT, MEDIAN, ROUND, ROUNDUP, ROUNDDOWN, INT, TRUNC, ABS, SIGN, MOD, POWER, SQRT, EXP, LN, LOG, LOG10, PI, CEILING, FLOOR, RAND, RANDBETWEEN, SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, AVERAGEIFS, SUMPRODUCT, VLOOKUP, XLOOKUP, MATCH, INDEX, CONCAT, CONCATENATE, TEXTJOIN, LEFT, RIGHT, MID, LEN, UPPER, LOWER, PROPER, TRIM, SUBSTITUTE, REPLACE, FIND, SEARCH, REPT, VALUE, EXACT, TEXT (number formats), TODAY, NOW, DATE, YEAR, MONTH, DAY. Anything else is kept as a call and listed so you can implement it. Need the data too? Turn the sheet into an array with Excel to JavaScript array.
Tools that pair well with the Excel Formula to JavaScript
- Excel Formula to Python — Paste an Excel or Google Sheets formula and get a Python function with clean variable names, the right imports and helpers for SUMIFS, VLOOKUP and Excel-style rounding.
- Excel Formula to PHP — Paste a spreadsheet formula and get a PHP 8 function: parenthesised ternaries, mb_* string functions, and helpers for lookups, conditional sums and Excel-style MOD.
- Excel Formula to SQL — Paste an Excel formula and get the equivalent SQL expression or SELECT query — IF and IFS as CASE WHEN, SUMIFS and COUNTIFS as conditional aggregates, and the right string and date functions for your database.
- JavaScript Formatter — Unminify and pretty-print JavaScript, JSON or JSX with your preferred indentation and brace style — or strip whitespace and comments with a verified minifier.
Frequently asked questions
Does the generated JavaScript give the same results as Excel?
A2 + 30 needs adapting.Can I use it for Google Sheets formulas or Apps Script?
What happens to functions it does not know?
networkdays(…)) and listed above the output so you can implement or replace them.Is my formula sent to a server?
How are cell references named?
B2 stays B2 and A2:A10 becomes A2_A10. Type a name next to any reference to rename it everywhere in the output.