Skip to content

Script Engine

Script Editor

The Script Engine lets you write custom JavaScript functions that become available as spreadsheet formulas. Define a function in the script editor and call it from any cell using =MYFUNC(args).

Opening the Script Editor

Open via Tools > Script Editor in the menu bar. The editor panel contains a code textarea, a Run button, and a status area.

Writing Custom Functions

Write standard JavaScript functions in the editor. Both function declarations and const/let arrow functions are detected:

// Simple function
function DOUBLE(x) {
  return x * 2;
}

// Arrow function
const GREET = (name) => "Hello, " + name + "!";

// Multi-argument function
function HYPOTENUSE(a, b) {
  return Math.sqrt(a * a + b * b);
}

After writing your functions, click Run (or the save button). The status message shows how many functions were registered.

Using Custom Functions in Cells

Once registered, call functions by name in any cell formula:

=DOUBLE(A1)
=GREET("World")
=HYPOTENUSE(3, 4)

Function names are case-insensitive. =double(5) and =DOUBLE(5) both work.

Async Functions and Fetch

Custom functions can be async and use fetch to retrieve data from APIs:

async function STOCKPRICE(symbol) {
  const resp = await fetch("https://api.example.com/price/" + symbol);
  const data = await resp.json();
  return data.price;
}

While an async function is resolving, the cell displays #LOADING.... Once the promise resolves, the grid re-renders with the final value.

Persistence

  • Scripts are saved to localStorage when you click Run, so they survive page reloads.
  • Scripts are also included in workbook serialization (URL sharing and Supabase storage).
  • On load, saved scripts are automatically compiled and functions are registered.

Error Handling

  • If the script contains a syntax error, a compilation error message appears in the status area.
  • If a function is called with invalid arguments at runtime, standard JavaScript errors propagate (e.g. the cell may show an error value).
  • Functions that do not exist return #NAME?.

Scope and Limitations

  • Functions run in the browser context. They have access to standard JavaScript APIs but not to the spreadsheet's internal objects.
  • Each Run replaces all previously registered custom functions.
  • Only functions explicitly declared in the script are registered; helper variables or closures are not exposed as cell functions.