Office-Addin-Scripts

repository·master·Indexed 41 days ago

https://github.com/officedev/office-addin-scripts

A collection of tools and libraries to automate Office Add-in development. Includes the office-addin-cli for management, office-addin-debugging for orchestration, office-addin-dev-certs for SSL management, and office-addin-cache for clearing cache folders. Also provides ESLint plugins (eslint-plugin-office-addins, eslint-plugin-excel-custom-functions) and metadata generation tools (CustomFunctionsMetadataPlugin, custom-functions-metadata) for Excel custom functions.

Tokens
60.7K
Snippets
247
Records
285
Agent score
51%

What's inside Office-Addin-Scripts

  1. Overview of Office-Addin-Scripts packages

    master

    This repository contains several packages designed to assist with Office Add-in development. Key packages include:

    • custom-functions-metadata: Automatically generates metadata for custom functions from JSDoc tags and parameter types.
    • custom-functions-metadata-plugin: A WebPack plugin for generating custom function metadata.
    • office-addin-cache: Clears the Office add-ins cache.
    • office-addin-cli: A command-line interface for Office Add-ins.
    • office-addin-debugging: Orchestrates debugging by managing dev-servers, dev settings, and sideloading add-ins.
    • office-addin-dev-certs: Manages HTTPS certificates for local development.
    • office-addin-dev-settings: Configures developer settings for an add-in.
    • office-addin-lint: Ensures code quality and standardizes formatting.
    • office-addin-manifest: Parses, displays, and modifies Office Add-in manifest files.
    • office-addin-mock: Provides a way to unit test the Office JavaScript API.
    • office-addin-node-debugger: Uses a Node instance as a proxy for debugging JavaScript runtimes in Office applications.
    • office-addin-project: Provides project-wide commands, such as conversion.
    • office-addin-sso: Handles Azure Active Directory registration and SSO infrastructure for taskpane add-ins.
    • office-addin-test-helpers: Tools for validating add-ins, compatible with office-addin-test-server and Mocha.
    • office-addin-test-server: A framework for testing taskpane add-ins by allowing them to send results to a test server.
    • office-addin-usage-data: Sends telemetry (events/exceptions) to infrastructure like ApplicationInsights.
  2. Implement a cancelable custom function with @cancelable

    master

    A function can perform specific actions when a user cancels the function execution.

    Requirements:

    • Use the @cancelable tag (though it is automatically detected if the last parameter is of type CustomFunctions.CancelableInvocation).
    • The last parameter must be of type CustomFunctions.CancelableInvocation.
    • Assign a callback to the oncanceled property of that parameter to define the cancellation behavior.
    • Constraints: A function cannot have both @cancelable and @streaming tags.
    /**
     * @customfunction LONG_TASK
     * @param invocation
     */
    function longTask(invocation: CustomFunctions.CancelableInvocation): void {
      invocation.oncanceled = () => {
        console.log("Task was canceled");
      };
    }
  3. Access cell and parameter addresses with @requiresAddress and @requiresParameterAddresses

    master

    If your custom function needs to know where it is being evaluated or where its inputs are located, use these tags.

    • @requiresAddress: Indicates the address of the cell where the function is being evaluated should be provided. The last parameter must be of type CustomFunctions.Invocation or a derived type. The address property will contain the cell address.
    • @requiresParameterAddresses: Indicates the addresses of the input parameters should be provided. The last parameter must be of type CustomFunctions.Invocation or a derived type. The parameterAddresses property will contain an array of addresses for each parameter.
  4. Use @linkedEntityLoadService for LinkedEntityDataDomains

    master

    The @linkedEntityLoadService tag marks a special custom function used as the loadFunction for user-defined LinkedEntityDataDomains.

    Requirements:

    • Must accept and return a single non-repeating, non-optional, scalar parameter of type unknown.
    • Must not be an XLL-compatible custom function.
    • Must allow rich data as input.
    • Behavior: These functions are excluded from the autocomplete drop-down list and Formula Builder.
    • Constraints: Cannot be combined with @streaming, @volatile, @requiresAddress, @requiresParameterAddresses, @excludeFromAutoComplete, @action, or @capturesCallingObject.
  5. Implement a streaming custom function with @streaming

    master

    Streaming functions allow a function to return values over time rather than a single result.

    Requirements:

    • Use the @streaming tag.
    • The last parameter must be of type CustomFunctions.StreamingInvocation<ResultType>.
    • The function must return void.
    • Instead of returning a value, call setResult(result: ResultType) on the last parameter.
    • setResult() can be called with an Error to indicate a failure.
    • Constraints: Streaming functions cannot be marked as @volatile and cannot be used with @cancelable.
    /**
     * @customfunction STREAM_DATA
     * @param callback
     */
    function streamData(callback: CustomFunctions.StreamingInvocation<string>): void {
      // ... logic to produce data ...
      callback.setResult("First chunk");
      callback.setResult("Second chunk");
    }
  6. Use @action for Excel-triggered functions

    master

    The @action tag identifies a function that is run when a user-defined Action is triggered. These functions are intended to be called only by the Excel runtime.

    Requirements:

    • Must accept a single non-repeating, non-optional, scalar parameter of type unknown.
    • Must have a return type of void.
    • Must not be an XLL-compatible custom function.
    • Must allow rich data as input.
    • Behavior: These functions are excluded from the autocomplete drop-down list and Formula Builder.
    • Constraints: Cannot be combined with @linkedEntityLoadService, @capturesCallingObject, @streaming, @volatile, or @excludeFromAutoComplete.