Skip to main content

Module python

Module python 

Source
Expand description

Python cells: the code a cell holds, its last result, and the text forms around it (the PY("…",0|1) formula of the function’s syntax, and the xl("…") references inside it). An xlsx file keeps the code in its Python part instead (see the xlsx crate).

Structs§

PyCode
A Python cell.
PyOutput
A Python result kept on the cell.
XlCall
An xl() call in Python code.

Constants§

BLOCKED
The value a Python cell shows when it can’t run: #BLOCKED!.
FILE_PREFIX
The prefix files put before PY(, as Excel writes it ([MS-XLSX]: _xlfn._xlws.PY).
MAX_FORMULA_CHARS
Excel’s limit on the characters of one formula. A Python cell’s code must fit in it once it is written as the PY formula of the function’s syntax (PyCode::to_file_formula): quotes are doubled and every 255 characters add "&", so the limit on the code itself depends on what the code holds.
MAX_RESULT_CELLS
The most cells a Python result may have (a crafted file can claim any size).

Functions§

is_py_formula
Whether text (a formula, with or without =) is a PY( call: such formulas are Python cells, set with python.set.
normalize_code
Line breaks as \n.
rewrite_xl
Rewrites the reference of every xl("…") literal in code with f; None from f leaves it. Returns the new code when anything changed. A new reference holding the literal’s quote (a sheet name that needs quotes, 'Q4 2026'!B2) gets the other quote as its delimiter, or an escaped quote when it holds both, so it never ends the string early.
xl_calls
The xl(…) calls in code, skipping comments and other string literals. A call whose first argument isn’t a plain string literal has no reference: the cells it reads are only known when it runs.