npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@microsoft/office-js

v1.1.99

Published

Office JavaScript APIs

Downloads

74,439

Readme

NPM Deployment Status

Office JavaScript APIs

The JavaScript API for Office enables you to create web applications that interact with the object models in Office host applications. Your application will reference the office.js library, which is a script loader. The office.js library loads the object models applicable to the Office application running the add-in.

About the NPM package

The NPM package for Office.js is a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.

The Office.js CDN contains all currently available Office.js APIs at any moment in time.

Each Office.js NPM package contains only Office.js APIs available on the Office.js CDN when the NPM package version was created.

Target scenarios

The NPM package for Office.js is intended as a way to obtain an offline copy (non-CDN) of the Office.js files, which can then be statically serve from your own site instead of using the CDN.

This NPM package is provided for the following scenarios.

  1. Development of an add-in behind a firewall, when accessing the Office.js CDN isn't possible.
  2. Offline access to the Office.js APIs to facilitate offline debugging.

Important: Office Add-ins published to AppSource must use the CDN reference. Offline Office.js references are only appropriate for internal development and debugging scenarios.

Best practices

Best practices for using the Office.js NPM package include:

Support

The Office.js CDN is the official supported source for Office Add-ins.

For the NPM package sourced through this repository, only the latest version of the package is supported. No support and no patches will be provided for previous versions of the package. The frequency of the updates to this repository and related NPM package to match the CDN version is not guaranteed.

Outlook add-ins don't support hosting Office.js offline due to network access requirements for dependencies like the Microsoft Ajax library.

Install the NPM package

To install "office-js" locally via the NPM package, run the following command.

npm install @microsoft/office-js --save

Our policy requires that developers always reference the latest version of Office.js library. This is to ensure that essential product updates are served quickly to the Office Add-ins by always referencing the latest release of the library for a given version, such as Generally Available (GA) version. Given that the latest Office.js release is backward-compatible with prior releases, it's safe to update to the most recent release of the library when one is available. Hence, only the latest version of Office.js NPM package is made available for installation.

Use the NPM package

Installing the NPM package locally creates a set of static Office.js files in the node_modules\@microsoft\office-js\dist folder of the directory where you ran the npm install command. To use the NPM package, do the following:

  1. Either manually or as part of a build script (e.g., CopyWebpackPlugin if you're using Webpack) have the files served from a destination of your choosing (e.g., from the /assets/office-js/ directory of your web server).

  2. Reference that location in a <script> tag within the HTML file in your add-in project.

For example, if you add the contents of the dist folder to the assets/office-js directory of your project, then you'd add the following <script> tag to your HTML file:

<script src="/assets/office-js/office.js"></script>

IntelliSense definitions

TypeScript definitions for Office.js are available.

Use TypeScript definitions with the NPM package

If you're using the Office.js NPM package for the firewall scenario and want a d.ts file that precisely matches the JS contents, use the d.ts file that's located within the /dist/office.d.ts folder of the NPM package. Achieve this by using a triple-slash reference.

  • TIP: If you create a references.ts file at the root of the project, simply point the reference to office.d.ts there.

If you don't need the firewall scenario, don't use the Office.js NPM package. Obtain the TypeScript definitions by using @types/office-js and reference the Office.js CDN at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.

Enable IntelliSense in Visual Studio

Visual Studio 2017+ can use these same TypeScript definitions, even for regular JavaScript. For JavaScript IntelliSense in earlier versions of Visual Studio, an office-vsdoc.js is available alongside the office.js file. As long as you have a Scripts/_references.js file in your VS project, and as long as you substitute the existing triple-slash reference (/// <reference path="https://.../office.js" />) with the new location (the -vsdoc part gets substituted automatically, so use it just as you would in a <script src=""> reference), you should have the corresponding JavaScript IntelliSense.

NPM Package Versions

Office.js versioning is described in detail in https://learn.microsoft.com/office/dev/add-ins/develop/referencing-the-javascript-api-for-office-library-from-its-cdn. Importantly, there's a difference between what's in the JS files versus what are the capabilities of a particular computer (i.e., older or slower-to-update versions of Office).

The NPM package and the repo branches assume the following structure.

| GitHub branch name | NPM tag name | Description | | ------------------ |-------------- |-------------| | release | latest | Identical to a previous release on https://appsforoffice.microsoft.com/lib/1/hosted/office.js The latest released publicly-available APIs. | | beta | beta | Identical to a previous release on https://appsforoffice.microsoft.com/lib/beta/hosted/office.js Forthcoming APIs, not necessarily ready for public consumption that may change. Possibly available on Insider Fast (and maybe Insider Slow) builds. |

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More info

For more information on Office Add-ins and the Office JavaScript APIs, see:

Join the Microsoft 365 Developer Program

Join the Microsoft 365 Developer Program to get resources and information to help you build solutions for the Microsoft 365 platform, including recommendations tailored to your areas of interest.

You might also qualify for a free developer subscription that's renewable for 90 days and comes configured with sample data; for details, see the FAQ.