Skip to content

Commit 843e5bf

Browse files
author
github-actions
committed
Merge branch 'main' into live
2 parents 14ad0dc + dfc66ca commit 843e5bf

File tree

2 files changed

+56
-49
lines changed

2 files changed

+56
-49
lines changed

.openpublishing.publish.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"word-js-1.4-hidden-document",
6969
"word-js-1.5-hidden-document",
7070
"word-js-desktop-1.1",
71+
"word-js-desktop-1.2",
7172
"word-js-online"
7273
],
7374
"open_to_public_contributors": true,

docs/develop/create-addin-commands.md

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Create add-in commands with the add-in only manifest
33
description: Configure an add-in only manifest to define add-in commands for Excel, Outlook, PowerPoint, and Word. Use add-in commands to create UI elements, add buttons or menus, and perform actions.
4-
ms.date: 09/05/2024
4+
ms.date: 02/28/2025
55
ms.localizationpriority: medium
66
---
77

@@ -37,15 +37,15 @@ The following example shows the **\<VersionOverrides\>** element and its child e
3737
...
3838
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
3939
<Requirements>
40-
<!-- add information about requirement sets -->
40+
<!-- Add information about requirement sets. -->
4141
</Requirements>
4242
<Hosts>
4343
<Host xsi:type="Workbook">
44-
<!-- add information about form factors -->
44+
<!-- Add information about form factors. -->
4545
</Host>
4646
</Hosts>
4747
<Resources>
48-
<!-- add information about resources -->
48+
<!-- Add information about resources. -->
4949
</Resources>
5050
</VersionOverrides>
5151
...
@@ -69,7 +69,7 @@ The following example shows the **\<Hosts\>**, **\<Host\>**, and **\<DesktopForm
6969
<Host xsi:type="Workbook">
7070
<DesktopFormFactor>
7171

72-
<!-- information about FunctionFile and ExtensionPoint -->
72+
<!-- Information about FunctionFile and ExtensionPoint. -->
7373

7474
</DesktopFormFactor>
7575
</Host>
@@ -82,21 +82,21 @@ The following example shows the **\<Hosts\>**, **\<Host\>**, and **\<DesktopForm
8282

8383
### Step 3: Add the FunctionFile element
8484

85-
The [**\<FunctionFile\>** element](/javascript/api/manifest/functionfile) specifies a file that contains JavaScript code to run when an add-in command uses the **ExecuteFunction** action. The **\<FunctionFile\>** element's **resid** attribute is set to a HTML file that includes all the JavaScript files your add-in commands require. You can't link directly to a JavaScript file. You can only link to an HTML file. The file name is specified as a [**\<Url\>** element](/javascript/api/manifest/url) in the [**\<Resources\>** element](/javascript/api/manifest/resources).
85+
The [**\<FunctionFile\>** element](/javascript/api/manifest/functionfile) specifies a file that contains JavaScript or TypeScript code to run when an add-in command uses the **ExecuteFunction** action. The **\<FunctionFile\>** element's **resid** attribute is set to a HTML file that includes all the JavaScript or TypeScript files your add-in commands require. You can't link directly to a JavaScript or TypeScript file. You can only link to an HTML file. The file name is specified as a [**\<Url\>** element](/javascript/api/manifest/url) in the [**\<Resources\>** element](/javascript/api/manifest/resources).
8686

8787
> [!NOTE]
88-
> The Yo Office projects use [webpack](https://webpack.js.org/concepts/) to avoid manually adding the JavaScript to the HTML.
88+
> The Yo Office projects use [webpack](https://webpack.js.org/concepts/) to avoid manually adding the JavaScript or TypeScript to the HTML.
8989
9090
The following is an example of the **\<FunctionFile\>** element.
9191

9292
```xml
9393
<DesktopFormFactor>
9494
<FunctionFile resid="Commands.Url" />
9595
<ExtensionPoint xsi:type="PrimaryCommandSurface">
96-
<!-- information about this extension point -->
96+
<!-- Information about this extension point. -->
9797
</ExtensionPoint>
9898

99-
<!-- You can define more than one ExtensionPoint element as needed -->
99+
<!-- You can define more than one ExtensionPoint element as needed. -->
100100
</DesktopFormFactor>
101101
```
102102

@@ -119,7 +119,7 @@ The following examples show how to use the **\<ExtensionPoint\>** element with *
119119
```xml
120120
<ExtensionPoint xsi:type="PrimaryCommandSurface">
121121
<CustomTab id="Contoso Tab">
122-
<!-- If you want to use a default tab that comes with Office, remove the above CustomTab element, and then uncomment the following OfficeTab element -->
122+
<!-- If you want to use a default tab that comes with Office, remove the above CustomTab element, and then uncomment the following OfficeTab element. -->
123123
<!-- <OfficeTab id="TabData"> -->
124124
<Label resid="residLabel4" />
125125
<Group id="Group1Id12">
@@ -131,32 +131,33 @@ The following examples show how to use the **\<ExtensionPoint\>** element with *
131131
</Icon>
132132
<Control xsi:type="Button" id="Button1Id1">
133133

134-
<!-- information about the control -->
134+
<!-- Information about the control. -->
135135
</Control>
136-
<!-- other controls, as needed -->
136+
<!-- Other controls, as needed. -->
137137
</Group>
138138
</CustomTab>
139139
</ExtensionPoint>
140140
<ExtensionPoint xsi:type="ContextMenu">
141141
<OfficeMenu id="ContextMenuCell">
142142
<Control xsi:type="Menu" id="ContextMenu2">
143-
<!-- information about the control -->
143+
<!-- Information about the control. -->
144144
</Control>
145-
<!-- other controls, as needed -->
145+
<!-- Other controls, as needed. -->
146146
</OfficeMenu>
147147
</ExtensionPoint>
148148
```
149149

150150
### Step 5: Add Control elements
151151

152-
The [**\<Control\>** element](/javascript/api/manifest/control) defines the usable surface of command (button, menu, etc) and the action associated with it.
152+
The [**\<Control\>** element](/javascript/api/manifest/control) defines the usable surface of command, such as a button or menu, and the action associated with it.
153153

154154
#### Button controls
155155

156-
A [button control](/javascript/api/manifest/control-button) performs a single action when the user selects it. It can either execute a JavaScript function or show a task pane. The following example shows how to define two buttons. The first button runs a JavaScript function without showing a UI, and the second button shows a task pane. In the **\<Control\>** element:
156+
A [button control](/javascript/api/manifest/control-button) performs a single action when the user selects it. It can either run a JavaScript or TypeScript function or show a task pane. The following example shows how to define two buttons. The first button runs a JavaScript function without showing a UI, and the second button shows a task pane. In the **\<Control\>** element:
157157

158158
- The **type** attribute is required, and must be set to **Button**.
159159
- The **id** attribute of the **\<Control\>** element is a string with a maximum of 125 characters.
160+
- The **xsi:type** attribute of the child [**\<Action\>** element](/javascript/api/manifest/action) must be set to **ExecuteFunction** to run a function or **ShowTaskpane** to display a task pane.
160161

161162
```xml
162163
<!-- Define a control that calls a JavaScript function. -->
@@ -194,46 +195,14 @@ A [button control](/javascript/api/manifest/control-button) performs a single ac
194195
</Control>
195196
```
196197

197-
The following code shows an example function used by **\<FunctionName\>**. Note the call to [`event.completed`](/javascript/api/office/office.addincommands.event#office-office-addincommands-event-completed-member(1)). This signals that you've successfully handled the event. When a function is called multiple times, such as multiple clicks on the same add-in command, all events are automatically queued. The first event runs automatically, while the other events remain on the queue. When your function calls `event.completed`, the next queued call to that function runs. You must implement `event.completed`, otherwise your function won't run.
198-
199-
```js
200-
// Initialize the Office Add-in.
201-
Office.onReady(() => {
202-
// If needed, Office.js is ready to be called
203-
});
204-
205-
// The command function.
206-
async function highlightSelection(event) {
207-
208-
// Implement your custom code here. The following code is a simple Excel example.
209-
try {
210-
await Excel.run(async (context) => {
211-
const range = context.workbook.getSelectedRange();
212-
range.format.fill.color = "yellow";
213-
await context.sync();
214-
});
215-
} catch (error) {
216-
// Note: In a production add-in, notify the user through your add-in's UI.
217-
console.error(error);
218-
}
219-
220-
// Calling event.completed is required. event.completed lets the platform know that processing has completed.
221-
event.completed();
222-
}
223-
224-
// You must register the function with the following line.
225-
Office.actions.associate("highlightSelection", highlightSelection);
226-
227-
```
228-
229198
#### Menu controls
230199

231200
A [menu control](/javascript/api/manifest/control-menu) can be used with either **PrimaryCommandSurface** or **ContextMenu**, and defines:
232201

233202
- A root-level menu item.
234203
- A list of submenu items.
235204

236-
When used with **PrimaryCommandSurface**, the root menu item displays as a button on the ribbon. When the button is selected, the submenu displays as a drop-down list. When used with **ContextMenu**, a menu item with a submenu is inserted on the context menu. In both cases, individual submenu items can either execute a JavaScript function or show a task pane. Only one level of submenus is supported at this time.
205+
When used with **PrimaryCommandSurface**, the root menu item displays as a button on the ribbon. When the button is selected, the submenu displays as a drop-down list. When used with **ContextMenu**, a menu item with a submenu is inserted on the context menu. In both cases, individual submenu items can either run a JavaScript or TypeScript function or show a task pane. Only one level of submenus is supported at this time.
237206

238207
The following example shows how to define a menu item with two submenu items. The first submenu item shows a task pane, and the second submenu item runs a JavaScript function. In the **\<Control\>** element:
239208

@@ -288,6 +257,43 @@ The following example shows how to define a menu item with two submenu items. Th
288257
</Control>
289258
```
290259

260+
#### Sample code for function commands
261+
262+
The following code shows a function that's invoked by a button or menu item control whose **\<Action\>** element's **xsi:type** is set to **ExecuteFunction**. Note the following about the code.
263+
264+
- The [Office.actions.associate](/javascript/api/office/office.actions#office-office-actions-associate-member(1)) call tells Office which function to run when a button or menu item is selected. The value passed to its **actionId** parameter must match the value specified in the [**\<FunctionName\>** element](/javascript/api/manifest/action#functionname) of the manifest. You must have an `Office.actions.associate` call for every function command defined in the manifest.
265+
- The [event.completed](/javascript/api/office/office.addincommands.event#office-office-addincommands-event-completed-member(1)) call signals that you've successfully handled the event. When a function is called multiple times, such as multiple clicks on the same add-in command, all events are automatically queued. The first event runs automatically, while the other events remain on the queue. When your function calls `event.completed`, the next queued call to that function runs. You must implement `event.completed`, otherwise your function won't run.
266+
267+
```js
268+
// Initialize the Office Add-in.
269+
Office.onReady(() => {
270+
// If needed, Office.js is ready to be called.
271+
});
272+
273+
// The command function.
274+
async function highlightSelection(event) {
275+
276+
// Implement your custom code here. The following code is a simple Excel example.
277+
try {
278+
await Excel.run(async (context) => {
279+
const range = context.workbook.getSelectedRange();
280+
range.format.fill.color = "yellow";
281+
await context.sync();
282+
});
283+
} catch (error) {
284+
// Note: In a production add-in, notify the user through your add-in's UI.
285+
console.error(error);
286+
}
287+
288+
// Calling event.completed is required. The event.completed call lets the platform know that processing has completed.
289+
event.completed();
290+
}
291+
292+
// This maps the function to the action ID specified in the manifest.
293+
Office.actions.associate("highlightSelection", highlightSelection);
294+
295+
```
296+
291297
### Step 6: Add the Resources element
292298

293299
The [**\<Resources\>** element](/javascript/api/manifest/resources) contains resources used by the different child elements of the **\<VersionOverrides\>** element. Resources include icons, strings, and URLs. An element in the manifest can use a resource by referencing the **id** of the resource. Using the **id** helps organize the manifest, especially when there are different versions of the resource for different locales. An **id** has a maximum of 32 characters.

0 commit comments

Comments
 (0)