Office JavaScript APIs

repository·release·Indexed 21 days ago

https://github.com/officedev/office-js

JavaScript APIs for building Office Add-ins that extend Office applications such as Word, Excel, and Outlook using HTML, CSS, and JS. The library is officially supported via the Office Content Delivery Network (CDN), with TypeScript IntelliSense available through @types/office-js and @types/office-js-preview.

Tokens
1.3K
Snippets
5
Records
8
Agent score
74%

What's inside Office.js

  1. Get help with Office Add-in development

    release

    For questions regarding development or API usage, use the following community channels:

    • Stack Overflow: Use the office-js tag.
    • Microsoft Q&A: Use the Office Development tag.

    These channels are monitored by community experts and members of the Microsoft product team.

  2. Install IntelliSense definitions for Office.js

    release

    To get TypeScript support and IntelliSense for the Office JavaScript APIs, install the appropriate type definitions from DefinitelyTyped via npm.

    Choose the package based on whether you are using the standard release or the preview version of the API.

    # For the latest RELEASE version:
    npm install @types/office-js --save-dev
    
    # For the latest PREVIEW version:
    npm install @types/office-js-preview --save-dev
  3. Reference Office.js from the CDN

    release

    The official and supported way to use Office.js is via the Office Content Delivery Network (CDN). Do not use the npm package associated with this repository, as it is no longer officially supported. Referencing the CDN ensures your add-in receives the most up-to-date implementation and essential product updates automatically.

    Add the following <script> tag within the <head> section of your HTML file:

    <head>
        ...
        <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
    </head>

    Note: Government cloud environments may require a specific CDN URL. Refer to the official guidance for government cloud deployment for details.

  4. Identify the release type from a branch name

    release

    The getReleaseTypeFromBranchName function determines the ReleaseType of a deployment based on the provided Git branch name.

    • A branch named release returns ReleaseType.release.
    • A branch named beta returns ReleaseType.beta.
    • A branch starting with the prefix custom returns ReleaseType.custom.
    • Any other branch name returns ReleaseType.none.
    import { getReleaseTypeFromBranchName, ReleaseType } from './ReleaseType';
    
    const type = getReleaseTypeFromBranchName('beta'); // Returns ReleaseType.beta
    const customType = getReleaseTypeFromBranchName('custom-feature-x'); // Returns ReleaseType.custom
    const unknownType = getReleaseTypeFromBranchName('main'); // Returns ReleaseType.none
  5. Environment variables for @microsoft/office-js-deployment-script

    release

    The @microsoft/office-js-deployment-script package uses specific environment variables to manage deployment workflows, particularly for Travis CI and NPM publishing. When configuring your deployment environment, ensure the following keys are available:

    • TRAVIS: Boolean (set to "true" to enable Travis-specific logic).
    • TRAVIS_BRANCH: The name of the current branch (the script automatically strips the refs/heads/ prefix if present).
    • TRAVIS_PULL_REQUEST: Boolean (set to "true" if the build is triggered by a pull request).
    • TRAVIS_BUILD_DIR: The directory path of the current build.
    • NPM_TOKEN: A valid NPM authentication token used for publishing packages to the NPM registry. You can generate this using npm token create (requires NPM version 5.5.1+).
    TRAVIS: boolean
    TRAVIS_BRANCH: string
    TRAVIS_PULL_REQUEST: boolean
    TRAVIS_BUILD_DIR: string
    NPM_TOKEN: string
  6. Use the ReleaseType enum

    release

    The ReleaseType enum defines the supported deployment categories used by the deployment script:

    • release: Standard production releases.
    • beta: Beta/testing releases.
    • custom: Custom deployments (identified by a custom prefix in the branch name).
    • none: No recognized release type.
    export enum ReleaseType {
      release = "release",
      beta = "beta",
      custom = "custom",
      none = "none",
    }