@microsoft/office-js
Version:
Office JavaScript APIs
883 lines (852 loc) • 4.69 MB
TypeScript
// Type definitions for Office.js 1.0
// Project: https://github.com/OfficeDev/office-js
// Definitions by: OfficeDev <https://github.com/OfficeDev>,
// Ricky Kirkham <https://github.com/Rick-Kirkham>,
// Alex Jerabek <https://github.com/AlexJerabek>,
// Elizabeth Samuel <https://github.com/ElizabethSamuel-MSFT>,
// Alison McKay <https://github.com/alison-mk>,
// Sam Ramon <https://github.com/samantharamon>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/*
office-js
Copyright (c) Microsoft Corporation
*/
////////////////////////////////////////////////////////////////
//////////////////// Begin Office namespace ////////////////////
////////////////////////////////////////////////////////////////
declare namespace Office {
/** A Promise object. Promises can be chained via ".then", and errors can be caught via ".catch".
* When a browser-provided native Promise implementation is available, Office.Promise will switch to use the native Promise instead.
*/
var Promise: IPromiseConstructor;
// **Note**: this is a copy of the PromiseConstructor object from
// https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2015.promise.d.ts
// It is necessary so that even with targeting "ES5" and not specifying any libs,
// developers will still get IntelliSense for "Office.Promise" just as they would with a regular Promise.
// (because even though Promise is part of standard lib.d.ts, PromiseConstructor is not)
interface IPromiseConstructor {
/**
* A reference to the prototype.
*/
readonly prototype: Promise<any>;
/**
* Creates a new Promise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: (T | PromiseLike<T>)[]): Promise<T[]>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<T1 | T2 | T3 | T4 | T5 | T6>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<T1 | T2 | T3 | T4 | T5>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<T1 | T2 | T3 | T4>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<T1 | T2 | T3>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<T1 | T2>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T>(values: (T | PromiseLike<T>)[]): Promise<T>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject(reason: any): Promise<never>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T>(reason: any): Promise<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | PromiseLike<T>): Promise<T>;
/**
* Creates a new resolved promise.
* @returns A resolved promise.
*/
resolve(): Promise<void>;
}
/**
* Gets the Context object that represents the runtime environment of the add-in and provides access to the top-level objects of the API.
*
* @remarks
*
* **Support details**
*
* A capital Y in the following matrix indicates that this property is supported in the corresponding Office host application.
* An empty cell indicates that the Office host application doesn't support this enumeration.
*
* For more information about Office host application and server requirements, see
* {@link https://docs.microsoft.com/office/dev/add-ins/concepts/requirements-for-running-office-add-ins | Requirements for running Office Add-ins}.
*
* *Supported hosts, by platform*
* <table>
* <tr><th> </th><th> Office on Windows </th><th> Office in web browser </th><th> Office on iPad </th><th> Outlook on mobile devices </th><th> Office on Mac </th></tr>
* <tr><td><strong> Excel </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Outlook </strong></td><td> Y </td><td> Y </td><td> </td><td> Y </td><td> Y </td></tr>
* <tr><td><strong> PowerPoint </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Project </strong></td><td> Y </td><td> </td><td> </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Word </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* </table>
*/
var context: Context;
/**
* Occurs when the runtime environment is loaded and the add-in is ready to start interacting with the application and hosted document.
*
* The reason parameter of the initialize event listener function returns an `InitializationReason` enumeration value that specifies how
* initialization occurred. A task pane or content add-in can be initialized in two ways:
*
* - The user just inserted it from Recently Used Add-ins section of the Add-in drop-down list on the Insert tab of the ribbon in the Office
* host application, or from Insert add-in dialog box.
*
* - The user opened a document that already contains the add-in.
*
* *Note*: The reason parameter of the initialize event listener function only returns an `InitializationReason` enumeration value for task pane
* and content add-ins. It does not return a value for Outlook add-ins.
*
* @remarks
*
* **Support details**
*
* A capital Y in the following matrix indicates that this method is supported in the corresponding Office host application.
* An empty cell indicates that the Office host application doesn't support this method.
*
* For more information about Office host application and server requirements, see
* {@link https://docs.microsoft.com/office/dev/add-ins/concepts/requirements-for-running-office-add-ins | Requirements for running Office Add-ins}.
*
* *Supported hosts, by platform*
* <table>
* <tr><th> </th><th> Office on Windows </th><th> Office in web browser </th><th> Office on iPad </th><th> Outlook on mobile devices </th><th> Office on Mac </th></tr>
* <tr><td><strong> Excel </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Outlook </strong></td><td> Y </td><td> Y </td><td> </td><td> Y </td><td> Y </td></tr>
* <tr><td><strong> PowerPoint </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Project </strong></td><td> Y </td><td> </td><td> </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Word </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* </table>
*
* @param reason Indicates how the app was initialized.
*/
function initialize(reason: InitializationReason): void;
/**
* Ensures that the Office JavaScript APIs are ready to be called by the add-in. If the framework hasn't initialized yet, the callback or promise
* will wait until the Office host is ready to accept API calls. Note that though this API is intended to be used inside an Office add-in, it can
* also be used outside the add-in. In that case, once Office.js determines that it is running outside of an Office host application, it will call
* the callback and resolve the promise with "null" for both the host and platform.
*
* @param callback - An optional callback method, that will receive the host and platform info.
* Alternatively, rather than use a callback, an add-in may simply wait for the Promise returned by the function to resolve.
* @returns A Promise that contains the host and platform info, once initialization is completed.
*/
function onReady(callback?: (info: { host: HostType, platform: PlatformType }) => any): Promise<{ host: HostType, platform: PlatformType }>;
/**
* Toggles on and off the `Office` alias for the full `Microsoft.Office.WebExtension` namespace.
*
* @remarks
*
* **Support details**
*
* A capital Y in the following matrix indicates that this method is supported in the corresponding Office host application.
* An empty cell indicates that the Office host application doesn't support this method.
*
* For more information about Office host application and server requirements, see
* {@link https://docs.microsoft.com/office/dev/add-ins/concepts/requirements-for-running-office-add-ins | Requirements for running Office Add-ins}.
*
* *Supported hosts, by platform*
* <table>
* <tr><th> </th><th> Office on Windows </th><th> Office in web browser </th><th> Office on iPad </th><th> Outlook on mobile devices </th><th> Office on Mac </th></tr>
* <tr><td><strong> Excel </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* <tr><td><strong> Outlook </strong></td><td> Y </td><td> Y </td><td> </td><td> Y </td><td> Y </td></tr>
* <tr><td><strong> PowerPoint </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* <tr><td><strong> Project </strong></td><td> Y </td><td> </td><td> </td><td> </td><td> </td></tr>
* <tr><td><strong> Word </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* </table>
*
* @param useShortNamespace True to use the shortcut alias; otherwise false to disable it. The default is true.
*/
function useShortNamespace(useShortNamespace: boolean): void;
/**
* Provides a method for associating action names with functions that carry out an action.
*/
const actions: Actions;
/**
* Represents the add-in.
*/
const addin: Addin;
/**
* Represents the Auth interface.
*/
const auth: Auth;
/**
* Represents the ribbon associated with the Office application.
*/
const ribbon: Ribbon;
/**
* Checks if the specified requirement set is supported by the host Office application.
* @param name - Set name; e.g., "MatrixBindings".
* @param minVersion - The minimum required version; e.g., "1.4".
*/
function isSetSupported(name: string, minVersion?: string): boolean;
// Enumerations
/**
* Provides options to determine the startup behavior of the add-in upon next start-up.
*/
enum StartupBehavior {
/**
* The add-in does not load until opened by the user.
*/
none = 'None',
/**
* Load the add-in but do not show UI.
*/
load = 'Load',
}
/**
* Visibility mode of the add-in.
*/
enum VisibilityMode {
/**
* UI is Hidden
*/
hidden = 'Hidden',
/**
* Displayed as taskpane
*/
taskpane = 'Taskpane',
}
/**
* Specifies the result of an asynchronous call.
*
* @remarks
*
* Returned by the `status` property of the {@link Office.AsyncResult | AsyncResult} object.
*/
enum AsyncResultStatus {
/**
* The call succeeded.
*/
Succeeded,
/**
* The call failed, check the error object.
*/
Failed
}
/**
* Specifies whether the add-in was just inserted or was already contained in the document.
*/
enum InitializationReason {
/**
* The add-in was just inserted into the document.
*/
Inserted,
/**
* The add-in is already part of the document that was opened.
*/
DocumentOpened
}
/**
* Specifies the host Office application in which the add-in is running.
*
* @remarks
* **Important**: In Outlook, this enum is available from Mailbox requirement set 1.5.
*/
enum HostType {
/**
* The Office host is Microsoft Word.
*/
Word,
/**
* The Office host is Microsoft Excel.
*/
Excel,
/**
* The Office host is Microsoft PowerPoint.
*/
PowerPoint,
/**
* The Office host is Microsoft Outlook.
*/
Outlook,
/**
* The Office host is Microsoft OneNote.
*/
OneNote,
/**
* The Office host is Microsoft Project.
*/
Project,
/**
* The Office host is Microsoft Access.
*
* **Important**: We no longer recommend that you create and use Access web apps and databases in SharePoint.
* As an alternative, we recommend that you use {@link https://powerapps.microsoft.com/ | Microsoft PowerApps}
* to build no-code business solutions for web and mobile devices.
*/
Access
}
/**
* Specifies the OS or other platform on which the Office host application is running.
*
* @remarks
* **Important**: In Outlook, this enum is available from Mailbox requirement set 1.5.
*/
enum PlatformType {
/**
* The platform is PC (Windows).
*/
PC,
/**
* The platform is Office on the web (in a browser).
*/
OfficeOnline,
/**
* The platform is Mac.
*/
Mac,
/**
* The platform is an iOS device.
*/
iOS,
/**
* The platform is an Android device.
*/
Android,
/**
* The platform is WinRT.
*/
Universal
}
// Objects
/**
* An object which encapsulates the result of an asynchronous request, including status and error information if the request failed.
*
* When the function you pass to the `callback` parameter of an "Async" method executes, it receives an AsyncResult object that you can access
* from the `callback` function's only parameter.
*/
interface AsyncResult<T> {
/**
* Gets the user-defined item passed to the optional `asyncContext` parameter of the invoked method in the same state as it was passed in.
* This returns the user-defined item (which can be of any JavaScript type: String, Number, Boolean, Object, Array, Null, or Undefined) passed
* to the optional `asyncContext` parameter of the invoked method. Returns Undefined, if you didn't pass anything to the asyncContext parameter.
*/
asyncContext: any;
/**
* Gets an object that may provide additional information if an {@link Office.Error | error} occurred.
*
* @remarks
*
* This property returns additional information if the following errors occur with these supported APIs.
*
* *Supported APIs*
*
* `Office.context.mailbox.item.getCallbackTokenAsync`, `Office.context.mailbox.item.getUserIdentityTokenAsync`
*
* *Supported errors*
* <table>
* <tr><th>`AsyncResult.error.name` </th><th>`AsyncResult.error.message` </th><th>Description of diagnostics object returned </th></tr>
* <tr><td><strong>HTTPRequestFailure</strong> </td><td>The request has failed. Please look at the diagnostics object for the HTTP error code. </td><td>The HTTP error code in a JSON object e.g., `{"HTTPCode":"401"}` </td></tr>
* <tr><td><strong>InternalServerError</strong></td><td>The Exchange server returned an error. Please look at the diagnostics object for more information.</td><td>The error message from the Exchange server in a JSON object e.g., `{"ErrorText": "The mailbox database is temporarily unavailable"}`</td></tr>
* </table>
*/
diagnostics: any;
/**
* Gets an {@link Office.Error} object that provides a description of the error, if any error occurred.
*/
error: Office.Error;
/**
* Gets the {@link Office.AsyncResultStatus} of the asynchronous operation.
*/
status: AsyncResultStatus;
/**
* Gets the payload or content of this asynchronous operation, if any.
*
* @remarks
*
* You access the AsyncResult object in the function passed as the argument to the callback parameter of an "Async" method, such as the
* `getSelectedDataAsync` and `setSelectedDataAsync` methods of the {@link Office.Document | Document} object.
*
* **Note**: What the value property returns for a particular "Async" method varies depending on the purpose and context of that method.
* To determine what is returned by the value property for an "Async" method, refer to the "Callback value" section of the method's topic.
*/
value: T;
}
/**
* Manages actions and keyboard shortcuts.
*/
interface Actions {
/**
* Associates the ID or name of an action with a function.
*
* @param actionId The ID of an action that is defined in an extended manifest or the name of the function as specified in a **FunctionName** element in the manifest.
* @param actionFunction The function that is run when the action is invoked.
*/
associate: (actionId: string, actionFunction: (arg?: any) => void) => void;
/**
* Replaces existing add-in shortcuts with custom shortcuts for the user.
*
* @remarks
*
* **Requirement sets**:
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/keyboard-shortcuts-requirement-sets | KeyboardShortcuts 1.1}
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*
* @param shortcuts An object of custom shortcuts with keys being the IDs of the actions (as defined in an extended manifest) and values being the shortcut combinations. For example, `{"SetItalic": "Ctrl+1", "SetBold": "Ctrl+2"}`.
* To learn how to specify a valid action ID and a key combination, see {@link https://docs.microsoft.com/office/dev/add-ins/design/keyboard-shortcuts | Add custom keyboard shortcuts to your Office Add-ins}. (Note that a key combination can be `null`, in which case, the action keeps the key combination specified in the JSON file.)
* @returns A promise that resolves when every custom shortcut assignment in `shortcuts` has been registered. Even if there is a conflict with existing shortcuts, the customized shortcut will be registered.
* Otherwise, the promise will be rejected with error code and error message. An "InvalidOperation" error code is returned if any action ID in `shortcuts` does not exist, or if shortcut combination is invalid.
*/
replaceShortcuts(shortcuts: {[actionId: string]: string}): Promise<void>;
/**
* Gets the existing shortcuts for the add-in. The set always includes (1) the shortcuts defined in the add-in's extended manifest for keyboard shortcuts and (2) the current user's custom shortcuts if those exist.
* The shortcut can be `null` if it conflicts with the shortcut of another add-in or with the Office application. Specifically, it would be `null` if, when prompted to choose which shortcut to use, the user didn't choose the action of the current add-in. For more information about conflicts with shortcuts, see {@link https://docs.microsoft.com/office/dev/add-ins/design/keyboard-shortcuts#avoid-key-combinations-in-use-by-other-add-ins | Avoid key combinations in use by other add-ins}.
*
* @remarks
*
* **Requirement sets**:
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/keyboard-shortcuts-requirement-sets | KeyboardShortcuts 1.1}
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*
* @returns A promise that resolves to an object of shortcuts, with keys being the IDs of the actions (as defined in an extended manifest) and values being the shortcut combinations. For example, `{"SetItalic": "Ctrl+1", "SetBold": "Ctrl+2", "SetUnderline": null}`.
*/
getShortcuts(): Promise<{[actionId: string]: string|null}>;
/**
* Checks if a set of shortcut combinations are currently in use for the user, as defined by another add-in or by the host Office application.
*
* @remarks
*
* **Requirement sets**:
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/keyboard-shortcuts-requirement-sets | KeyboardShortcuts 1.1}
*
* - {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*
* @param shortcuts An array of shortcut combinations. For example, `["Ctrl+1", "Ctrl+2"]`.
* @returns A promise that resolves to an array of objects. Each object consists of a shortcut combination and Boolean value. The value is `true` if the shortcut combination conflicts with a shortcut of another add-in or with a shortcut of the Office application; otherwise, `false`. For example, `[{shortcut:"Ctrl+1", inUse:true},{shortcut:"Ctrl+2", inUse:false}]`.
*/
areShortcutsInUse(shortcuts: string[]): Promise<{shortcut: string, inUse: boolean}[]>;
}
/**
* Message used in the `onVisibilityModeChanged` invocation.
*/
interface VisibilityModeChangedMessage {
/**
* Visibility changed state.
*/
visibilityMode: Office.VisibilityMode;
}
/**
* Represents add-in level functionality for operating or configuring various aspects of the add-in.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
interface Addin {
/**
* Sets the startup behavior for the add-in for when the document is opened next time.
* @param behavior - Specifies startup behavior of the add-in.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
setStartupBehavior(behavior: Office.StartupBehavior): Promise<void>;
/**
* Gets the current startup behavior for the add-in.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
getStartupBehavior(): Promise<Office.StartupBehavior>;
/**
* Shows the task pane associated with the add-in.
* @returns A promise that is resolved when the UI is shown.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
showAsTaskpane(): Promise<void>;
/**
* Hides the task pane.
* @returns A promise that is resolved when the UI is hidden.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
hide(): Promise<void>;
/**
* Adds a handler for the `onVisibilityModeChanged` event.
* @param handler - The handler function that is called when the event is emitted. This function takes in a message for the receiving component.
* @returns A promise that resolves to a function when the handler is added. Calling it removes the handler.
*
* @remarks
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/shared-runtime-requirement-sets | SharedRuntime 1.1}
*/
onVisibilityModeChanged(
handler: (message: VisibilityModeChangedMessage) => void,
): Promise<() => Promise<void>>;
}
/**
* An interface that contains all the functionality provided to manage the state of the Office ribbon.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
interface Ribbon {
/**
* Registers a custom contextual tab with Office and defines the tab's controls.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.2}
*
* This method only requests that the tab be registered. The actual registration is controlled by the Office application and may not be complete when the returned `Promise` object is resolved.
* For more information and code examples, see {@link https://docs.microsoft.com/office/dev/add-ins/design/contextual-tabs | Create custom contextual tabs}.
*
* @param tabDefinition - Specifies the tab's properties and child controls and their properties. Pass a JSON string that conforms to the Office dynamic-ribbon JSON schema to `JSON.parse`, and then pass the returned object to this method.
*/
requestCreateControls(tabDefinition: Object): Promise<void>;
/**
* Sends a request to Office to update the ribbon.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*
* Note that this API is only to request an update. The actual UI update to the ribbon is controlled by the Office application and hence the exact timing of the ribbon update (or refresh) cannot be determined by the completion of this API.
*
* For code examples, see {@link https://docs.microsoft.com/office/dev/add-ins/design/disable-add-in-commands | Enable and Disable Add-in Commands} and {@link https://docs.microsoft.com/office/dev/add-ins/design/contextual-tabs | Create custom contextual tabs}.
*
* @param input - Represents the updates to be made to the ribbon. Note that only the changes specified in the input parameter are made.
*/
requestUpdate(input: RibbonUpdaterData): Promise<void>;
}
/**
* Specifies changes to the ribbon, such as the enabled or disabled status of a button.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
interface RibbonUpdaterData {
/**
* Collection of tabs whose state is set with the call of `requestUpdate`.
*/
tabs: Tab[];
}
/**
* Represents an individual tab and the state it should have. For code examples, see {@link https://docs.microsoft.com/office/dev/add-ins/design/disable-add-in-commands | Enable and Disable Add-in Commands} and {@link https://docs.microsoft.com/office/dev/add-ins/design/contextual-tabs | Create custom contextual tabs}.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
interface Tab {
/**
* Identifier of the tab as specified in the manifest.
*/
id: string;
/**
* Specifies one or more of the controls in the tab, such as menu items, buttons, etc.
*
* @remarks
*
* When the `Tab` object is part of an {@link Office.RibbonUpdaterData} object passed to the `requestUpdate` method of {@link Office.Ribbon}, this property specifies the IDs of the controls whose enabled status is to be changed. However, if there is a `groups` property on the tab, then this property is ignored and the `controls` properties of the specified groups must be used to change enabled status.
*/
controls?: Control[];
/**
* Specifies whether the tab is visible on the ribbon. Used only with contextual tabs.
*
* @remarks
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.2}
*/
visible?: boolean;
/**
* Specifies one or more of the control groups on the tab.
*
* @remarks
*
* When the `Tab` object is part of an {@link Office.RibbonUpdaterData} object passed to the `requestUpdate` method of {@link Office.Ribbon}, the `controls` properties of the various {@link Office.Group} objects specify which controls have their enabled status changed; the `controls` property of the `Tab` object is ignored.
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
groups?: Group[];
}
/**
* Represents a group of controls on a ribbon tab.
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
interface Group {
/**
* Identifier of the group as specified in the manifest.
*
*/
id: string;
/**
* Specifies one or more of the controls in the group, such as menu items, buttons, etc.
*
* @remarks
*
* When the `Group` object is part of a {@link Office.RibbonUpdaterData} object passed to the `requestUpdate` method of {@link Office.Ribbon}, the `controls` properties of the various {@link Office.Group} objects specify which controls have their enabled status changed; the `controls` property of the `Group` object's parent `Tab` object is ignored.
*/
controls?: Control[];
}
/**
* Represents an individual control or command and the state it should have.
*
* @remarks
*
* For code samples showing how to use a `Control` object and its properties, see {@link https://docs.microsoft.com/office/dev/add-ins/design/disable-add-in-commands | Enable and Disable Add-in Commands} and {@link https://docs.microsoft.com/office/dev/add-ins/design/contextual-tabs | Create custom contextual tabs}.
*
* **Requirement set**: {@link https://docs.microsoft.com/javascript/api/requirement-sets/common/ribbon-api-requirement-sets | RibbonApi 1.1}
*/
interface Control {
/**
* Identifier of the control as specified in the manifest.
*/
id: string;
/**
* Indicates whether the control should be enabled or disabled. The default is true.
*/
enabled?: boolean;
}
/**
* Represents the runtime environment of the add-in and provides access to key objects of the API.
* The current context exists as a property of Office. It is accessed using `Office.context`.
*
* @remarks
*
* **Hosts**: Excel, Outlook, PowerPoint, Project, Word
*/
interface Context {
/**
* True, if the current platform allows the add-in to display a UI for selling or upgrading; otherwise returns False.
*
* @remarks
*
* **Hosts**: Excel, Word
*
* `commerceAllowed` is only supported in Office on iPad.
*
* The iOS App Store doesn't support apps with add-ins that provide links to additional payment systems. However, Office Add-ins running in
* Office on the Windows desktop or in the browser do allow such links. If you want the UI of your add-in to provide a link to an
* external payment system on platforms other than iOS, you can use the commerceAllowed property to control when that link is displayed.
*/
commerceAllowed: boolean;
/**
* Gets the locale (language) specified by the user for editing the document or item.
*
* @remarks
*
* The `contentLanguage` value reflects the **Editing Language** setting specified with **File \> Options \> Language** in the Office host
* application.
*
* **Support details**
*
* A capital Y in the following matrix indicates that this property is supported in the corresponding Office host application.
* An empty cell indicates that the Office host application doesn't support this enumeration.
*
* For more information about Office host application and server requirements, see
* {@link https://docs.microsoft.com/office/dev/add-ins/concepts/requirements-for-running-office-add-ins | Requirements for running Office Add-ins}.
*
* *Supported hosts, by platform*
* <table>
* <tr><th> </th><th> Office on Windows </th><th> Office in web browser </th><th> Office on iPad </th><th> Outlook on mobile devices </th><th> Office on Mac </th></tr>
* <tr><td><strong> Excel </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* <tr><td><strong> Outlook </strong></td><td> Y </td><td> Y </td><td> </td><td> Y </td><td> Y </td></tr>
* <tr><td><strong> PowerPoint </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* <tr><td><strong> Project </strong></td><td> Y </td><td> </td><td> </td><td> </td><td> </td></tr>
* <tr><td><strong> Word </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> </td></tr>
* </table>
*/
contentLanguage: string;
/**
* Gets information about the environment in which the add-in is running.
*
* @remarks
* **Important**: In Outlook, this property is available from Mailbox requirement set 1.5.
* For all Mailbox requirement sets, you can use the
* {@link https://docs.microsoft.com/javascript/api/outlook/office.mailbox?view=outlook-js-1.1&preserve-view=true#outlook-office-mailbox-diagnostics-member | Office.context.mailbox.diagnostics}
* property to get similar information.
*/
diagnostics: ContextInformation;
/**
* Gets the locale (language) specified by the user for the UI of the Office host application.
*
* @remarks
*
* The returned value is a string in the RFC 1766 Language tag format, such as en-US.
*
* The `displayLanguage` value reflects the current **Display Language** setting specified with **File \> Options \> Language** in the Office
* host application.
*
* When using in Outlook, the applicable modes are Compose or Read.
*
* **Support details**
*
* A capital Y in the following matrix indicates that this property is supported in the corresponding Office host application.
* An empty cell indicates that the Office host application doesn't support this enumeration.
*
* For more information about Office host application and server requirements, see
* {@link https://docs.microsoft.com/office/dev/add-ins/concepts/requirements-for-running-office-add-ins | Requirements for running Office Add-ins}.
*
* *Supported hosts, by platform*
* <table>
* <tr><th> </th><th> Office on Windows </th><th> Office in web browser </th><th> Office on iPad </th><th> Outlook on mobile devices </th><th> Office on Mac </th></tr>
* <tr><td><strong> Excel </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Outlook </strong></td><td> Y </td><td> Y </td><td> </td><td> Y </td><td> Y </td></tr>
* <tr><td><strong> PowerPoint </strong></td><td> Y </td><td> Y </td><td> Y </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Project </strong></td><td> Y </td><td> </td><td> </td><td> </td><td> Y </td></tr>
* <tr><td><strong> Word </strong></td><td> Y </td><td> </td><td> Y </td><td> </td><td> Y </td></tr>
* </table>
*/
displayLanguage: string;
/**
* Gets an object that represents the document the content or task pane add-in is interacting with.
*/
document: Office.Document;
/**
* Contains the Office application host in which the add-in is running.
*
* @remarks
* **Important**: In Outlook, this property is available from Mailbox requirement set 1.5. You can also use the
* `Office.context.diagnostics` property to get the host starting with requi