Macros let you write JavaScript that reads and writes the spreadsheets in your ELN. They run in a sandboxed environment with a hard 10-second timeout. The full mathjs library is available for numeric and statistical calculations.
For an overview of how to manage and run macros, see Spreadsheets.
Click Run. The target sheet’s A1 cell is set to the sum of the first ten cells of Sheet1’s column A, with a yellow background. The result row below the editor shows how many cells were written.
context — the spreadsheet API. Lets you read and write sheets, cells, and ranges across every spreadsheet section in the ELN.
math — the full mathjs library. All numeric, statistical, matrix, and unit operations work normally. A small set of code-execution functions are disabled for safety (evaluate, import, simplify, derivative, resolve, createUnit, reviver).
A macro takes effect entirely through the writes it queues (cell.set, range.set, setStyle, …). There is no output value to return — write your results into a sheet instead.
Returns the worksheet with the given name. Throws if no sheet matches — a typo surfaces immediately rather than silently doing nothing.
const plate = context.getSheet("Plate-1");
plate.cell("B2").set(42);
If two sections in the same ELN have a worksheet with the same name, getSheet returns the active section’s match first. Use getSheets() and filter manually for explicit disambiguation.
Returns the cell’s current value. Sees writes the macro has already queued — cell.set(42); cell.read() returns 42.
cell.set(value)
Queues a write. Strings starting with = are treated as formulas.
cell.setBlock(values)
Anchors a 2D array at this cell and queues writes for every element. Dimensions are inferred — handy when you don’t know how many rows a CSV will have. Returns the resulting Range.
cell.setStyle(style)
Queues a style write. style is a CSS-property map, e.g. { background: "#ffd", fontWeight: "bold" }.
cell.setMeta(meta)
Queues a per-cell metadata write — an arbitrary { key: value } payload persisted with the workbook.
A macro can read and write any spreadsheet section in the current ELN — not just the one it lives in.
Reads happen against a snapshot taken when the run starts. They’re always fast and synchronous.
Writes to the active section flow through the live spreadsheet immediately. The section auto-saves as usual.
Writes to other sections update that section’s saved data directly and trigger a save. The other section won’t visually refresh until the user reloads the ELN, but the data is persisted.
const plate = context.getSheet("Plate-1"); // in another section
const summary = context.getSheet("Summary"); // in this section
const od = plate.range("B2:B11").read().flat().filter(v => typeofv === "number");
summary.cell("A1").set("Mean OD");
summary.cell("B1").set(math.mean(od));
There is no conflict detection: if another user is editing a different section at the same time, the macro’s write wins on save.
The full mathjs function set is available except for these blocked functions: evaluate, simplify, derivative, resolve, import, createUnit, reviver. Calling any of them throws an error.
Add a debugger; statement, open your browser’s developer tools (F12), then click Run. Execution pauses on that line so you can inspect variables and step through the code.
With dev tools closed, debugger does nothing and the macro runs straight through. The 10-second timeout keeps counting while you are paused, so use it for a quick look — pausing too long terminates the run.