Referencing and writing to worksheet cells from Jet commands
Use Jet’s cell-reference operators to read data from cells, write values back, or place formulas — all from the Command Editor or inside a .jt script segment. This is the scripting-side complement to the formula bar: the formula bar lets you type expressions into cells; these operators let a running command reach out to cells.
The # operator
Section titled “The # operator”# references the active worksheet. #A1 is cell A1, #B2:B101 is a range, #D2 is cell D2. A single # at the start of a range is enough — you don’t repeat it before the second endpoint.
These operators are part of Jet’s syntax. Switch the Command Editor to Jet before using them. If Python or R is the active language and you want to manipulate cells programmatically, switch to Jet for that work — or place the cell-reference commands in a # %% jet segment of a mixed-language script.
Read from cells
Section titled “Read from cells”x = #B2:B101;Reads the range B2:B101 into a Jet variable x.
Write a value to a cell
Section titled “Write a value to a cell”#J1 = mean(#B2:B101)Reads B2:B101, computes the mean using Jet’s mean, writes the result to J1.
String assignment: formulas vs. text
Section titled “String assignment: formulas vs. text”Assigning a string to a cell mirrors typing into the formula bar:
- A string that starts with
=becomes a formula. - A string without a leading
=becomes literal cell text.
#J2 = "=AVERAGE(B2:B101)"Writes a formula to J2 — exactly as if you had clicked J2 and typed =AVERAGE(B2:B101) in the formula bar. The cell shows the computed average and recomputes whenever the B column changes.
#J3 = "=py::numpy.std(B2:B101)"Writes a Python formula to J3 — the cell uses Python’s numpy.std to compute the standard deviation. The py:: qualifier routes it to Python, just as it would in the formula bar.
Important distinction: the # operator is for Jet command syntax — outside of formula text. Inside a formula string, cell references like B2:B101 already refer to the active worksheet by default. So #J1 = mean(#B2:B101) uses # (it’s Jet code), but #J2 = "=AVERAGE(B2:B101)" doesn’t need # inside the quotes (the part inside the quotes is formula-bar text).
Explicit wrappers: _f() and _t()
Section titled “Explicit wrappers: _f() and _t()”When the auto-detection (leading = → formula, otherwise text) isn’t what you want, use the explicit wrappers:
_f() — force formula
Section titled “_f() — force formula”#J4 = _f("AVERAGE(B2:B101)")Same end result as #J2 = "=AVERAGE(B2:B101)" — the leading = is optional inside _f() because the wrapper itself signals “this is a formula.” _f() is useful when the formula text comes from a variable and you want to be unambiguous.
_t() — force text
Section titled “_t() — force text”#J5 = _t("=AVERAGE(B2:B101)")Writes the literal text =AVERAGE(B2:B101) to J5 — no formula evaluation. The cell displays the formula source as a string. _t() is useful when you want a string that happens to start with = to stay as text: a label, a header, a piece of documentation that shows a formula without computing it.
The leading underscores in _f() and _t() avoid collisions with user-defined functions named f or t.
Practical patterns
Section titled “Practical patterns”Populate a summary block from a script
Section titled “Populate a summary block from a script”#L1 = "Mean"; #M1 = mean(#B2:B101);#L2 = "Std"; #M2 = std(#B2:B101);#L3 = "Count"; #M3 = length(#B2:B101);Write formulas programmatically
Section titled “Write formulas programmatically”for i = 2:101 #("E" + string(i)) = _f("B" + string(i) + " * 1.8 + 32");endFills E2:E101 with Fahrenheit-conversion formulas that reference the corresponding B-column Celsius values.
Mixed-language scripts with cell I/O
Section titled “Mixed-language scripts with cell I/O”In a .jt mixed-language script, use a Jet segment for cell I/O and other segments for computation:
# %% jettemps = #B2:B101;
# %% pythonimport numpy as npresult = np.percentile(temps, [25, 50, 75])
# %% jet#L1 = "Q1"; #M1 = result(1);#L2 = "Med"; #M2 = result(2);#L3 = "Q3"; #M3 = result(3);See also
Section titled “See also”- Tutorial 2: Mixing languages in formula bar and scripts — where these operators fit in the polyglot model
- Tutorial 1: Your first analysis in MathJet — live linking between cells and charts