SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface IScript

    Contains interfaces for working with scripts.

    Scripts are collections of modules that contain functions.

    Modules are analogous to files, and functions are the executable code within those modules.

    interface IScript {
        isIScript: true;
        addListeners(
            listeners: IScript.IListeners,
            options?: IListener.Options,
        ): Remove;
        addModule(
            uid: string,
            module: IModule,
            options?: IModuleCollection.AddOptions,
        ): void;
        addModuleFromJSON(
            uid: string,
            json: CompiledModule,
            options?: IModuleCollection.AddOptions,
        ): Promise<IModule>;
        createModule(options?: CompileOptions): Promise<IModule | null>;
        executeMacro(
            functionName: string,
            moduleId?: string,
            options?: RunOptions,
        ): Promise<MacroResults>;
        getFunctionCategories(
            options?: IScript.GetCategoryOptions,
        ): Promise<IFunctionCollection.Category[]>;
        getModules(): IModuleCollection;
        isReadOnly(): boolean;
        run(
            script: string | CompiledModule,
            options?: RunOptions,
        ): Promise<RunResults>;
        searchFunctions(options?: IScript.SearchOptions): Promise<IFunction[]>;
        start(): Promise<void>;
        toJSON(): Record<string, IModule.JSON>;
    }
    Index
    isIScript: true

    For runtime type checking.

    • Registers a pre-compiled module from its IModule.JSON (the execute-half of createModule, with NO TypeScript compiler loaded).

      Parameters

      Returns Promise<IModule>

      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.

      Parameters

      • Optionaloptions: CompileOptions

      Returns Promise<IModule | null>

    • Executes a macro function - the user-invoked entry point.

      Parameters

      • functionName: string

        The name of the function to execute.

      • OptionalmoduleId: string

        The ID of the module containing the function.

      • Optionaloptions: RunOptions

      Returns Promise<MacroResults>

      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.

    • Returns if the script is readonly.

      Returns boolean

    • Runs a script's entry once against the workbook - the "make a change" primitive.

      Parameters

      Returns Promise<RunResults>

      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:

      • source (string) — TypeScript, compiled here (needs the TS compiler).
      • compiled (IModule.JSON) — an already-compiled module, run with NO compiler. This is the CSP-safe path for hosts that compile elsewhere: the VS Code webview's CSP blocks the CDN-loaded compiler, so the MCP server compiles on Node and ships the compiled module here for execution via a data: URL. (The compiler filters error-severity diagnostics before shipping, so a compiled module passed here is expected to be runnable.)
    • Will start scripting engine and autoRun scripts.

      Returns Promise<void>

    • Returns a JSON representation of the script.

      Returns Record<string, IModule.JSON>