Add Listeners.
Optionaloptions: IListener.OptionsAdds a module to the script.
Optionaloptions: IModuleCollection.AddOptionsRegisters a pre-compiled module from its IModule.JSON (the execute-half of createModule, with NO TypeScript compiler loaded).
Stable id the module is stored/serialized under.
A compiled module (IModule.JSON) — the module of a CompileResult.
Optionaloptions: IModuleCollection.AddOptions
Builds the module via the compiler-free data: URL path (same as run with a IModule.JSON) and adds it
to the collection. This is how a CSP-restricted host (the VS Code webview, which cannot compile)
persists an edited macro into the live workbook: the editor compiles on Node and ships the
compiled module here to register.
Creates a module from the source code.
Optionaloptions: CompileOptionsExecutes a macro function - the user-invoked entry point.
The name of the function to execute.
OptionalmoduleId: string
The ID of the module containing the function.
Optionaloptions: RunOptions
The macro's target comes from the selection (the sheet, the ranges, the range - whichever its first parameter declares), and so does where its result goes: a returned value is written into the selection (IScript.RunOptions.applyResult, on by default here and only here). To run a script for its answer rather than its effect, use run.
The categories the searchable functions declare, each with how many functions carry it.
Optionaloptions: IScript.GetCategoryOptions
The categories, ordered by name; counts are summed across every source searched.
The workbook-level IFunctionCollection.getCategories — a function picker builds its category list from this, so a module's custom functions show up in it (in their own category, or swelling the count of a built-in one they declare).
Returns a collection of modules.
Returns if the script is readonly.
Runs a script's entry once against the workbook - the "make a change" primitive.
TypeScript source, or a compiled IModule.JSON (the module of a CompileResult).
Optionaloptions: RunOptions
Unlike IFunctionCollection.add (which registers a reusable function), this is a one-shot:
the entry runs inside a single transaction and nothing is registered. That transaction becomes
an undo entry only if the entry actually wrote something - a run that only reads elides, so
there is no commit id, no event and nothing on the undo stack. The entry's return value is the
caller's result: it is reported back, never written into the workbook (contrast
executeMacro, the user-invoked path, which puts it at the selection). The entry
is the default export, authored as export default function (ctx: IScript.ScriptContext) { ... }
— one parameter, with the workbook as ctx.wb. A macro that wants "the selected" sheet/range
instead takes that target first and the context second ((sheet: ISheet, ctx)).
Changes are made via the workbook API in the body; observation is via ctx.log.
Accepts either form of the same script:
string) — TypeScript, compiled here (needs the TS compiler).data: URL. (The compiler filters error-severity diagnostics before shipping,
so a compiled module passed here is expected to be runnable.)Convenience method for creating a module from a file.
Optionaloptions: IScript.SearchOptionsequivalent to getModules().search( { type: 'macro', name } )
Searches every loaded module and — with IScript.SearchOptions.includeBuiltIn — the built-in functions, as ONE list: IScript.SearchOptions.limit and the relevance ordering of IFunctionCollection.search apply to the union, not to each source separately.
Will start scripting engine and autoRun scripts.
Contains interfaces for working with scripts.
Remarks
Scripts are collections of modules that contain functions.
Modules are analogous to files, and functions are the executable code within those modules.