Formulas
A formula starts with =. Its calculation uses the typed cell values, the references and names of the workbook and its date system. Formulas can add up a column, spill a dynamic array into neighboring cells or call functions that need data from your application.
Enter Formulas in a Cell
Select a cell and start typing =. When the formula expects a reference, use the arrow keys to choose a cell without committing the draft. Hold Shift with an arrow key to extend or shrink the referenced range. To select a range with the mouse, type =SUM(, drag across the cells, type ) and press Enter. Escape discards the draft. Press F2 or double-click a formula cell to edit its text, then press F2 again to choose references with the arrow keys. F2 toggles between Edit and Point modes without applying the draft. Ctrl+Arrow jumps to a data boundary; Ctrl+Shift+Arrow extends the reference to it in Point mode.
After a reference has been picked, Enter or Confirm adds any missing closing parentheses before applying the formula. Parentheses inside quoted text are ignored; unmatched quotes, trailing operators and surplus closing parentheses remain ordinary formula errors.
Lock References and Fill Selected Cells
With the cursor on a formula reference, F4 cycles A1 through $A$1, A$1, $A1 and back to A1. It also cycles the endpoints of a selected range reference. Parentheses, operators and text outside that reference are preserved.
To enter related formulas together, select C1:C3, type =A1+$B$1 and press Ctrl+Enter. The cells receive =A1+$B$1, =A2+$B$1 and =A3+$B$1. References are translated from the active cell being edited, including when it is not the first cell of the selection. The range stays selected and one Undo reverses the fill. See Keyboard and Accessibility for modes, navigation and validation behavior.
Write Formulas
The following code writes three amounts into A1:A3 of the first worksheet, adds them up, compares the total with a target and creates a dynamic array. editor is the Spreadsheet of the browser editor:
const sheet = editor.workbook.sheets.at(0);
sheet.range('A1:A3').setValues([[125], [275], [100]]);
sheet.cell('B1').setFormula('=SUM(A1:A3)');
sheet.cell('B2').setFormula('=IF(B1>400,"On target","Review")');
sheet.cell('D1').setFormula('=SEQUENCE(3,2)');
The code works as follows:
Range.setValueswrites the amounts intoA1:A3as typed values, andCell.setFormulawrites each formula with its leading equals sign.SUMinB1adds the amounts.IFinB2returnsOn targetwhen the total inB1is greater than 400, andReviewotherwise.SEQUENCEinD1returns an array of three rows and two columns. As a dynamic-array formula, it spills fromD1into the neighboring cells.
Look Up Functions in the Catalog
The function catalog contains descriptions, argument bounds, examples and flags for application-data providers and approximate functions. In code, FORMULA_FUNCTIONS holds the catalog as FormulaDefinition objects.
LET, LAMBDA and the supported higher-order and array functions are available through the catalog. Recognition of a function name is not a promise of full Excel parity for every input combination. Approximate functions are marked and should be assessed for the accuracy needs of the application.
Use References and Dynamic Arrays
A formula can refer to cells in several ways:
- Sheet-qualified references, such as
Sales!F2:F25, which name the worksheet of the cells. - Named ranges, described in Named Ranges and External References.
- Whole rows or columns, where supported.
- Structured table references, such as
[@Quantity]in a table.
Dynamic-array formulas spill into neighboring cells. Occupied or merged targets can produce #SPILL!, and editing a spill child can block the anchor. Array results keep their row and column dimensions.
Handle Calculation Errors
Handle calculation errors such as #REF!, #VALUE!, #N/A and spill errors as actual outcomes. Fix the references or the data, or choose an explicit report policy.
Warning
Errors Are Outcomes. Do not silently turn errors into zero totals.
Supply External Data With a Provider
Functions that need external application data require a provider, which you set with Workbook.setFormulaProvider. Fetch the data asynchronously in the host and cache it, then return a supported synchronous value from the provider, a FormulaProvider function.
Missing or throwing providers and unsupported values have defined error outcomes. The control does not automatically contact external services merely because an Excel function names one.
Configure Custom Functions and External Workbooks
Custom functions and supplied external workbooks are configured through WorkbookCalculation, which Workbook.calculation returns. Its registerFunction method registers a callback as a function, and setExternalWorkbook binds a snapshot of an already loaded workbook.
Executable callbacks belong to the application and are not serialized into XLSX or TXWB as executable code.
Next Steps
- Custom Functions and Formula Data: register custom functions and providers and keep them registered for the lifetime of their owner.
- Formula Functions: look up the syntax, arguments and availability of each function.
- Named Ranges and External References: name ranges and constants and refer to external workbooks.