Skip to content

[Excel/Word] (keyboard shortcuts) Create a unified manifest for the sample #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 23 additions & 109 deletions Samples/office-keyboard-shortcuts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,119 +1,33 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# TeamsFx files
env/.env.*.user
env/.env.local
appPackage/build

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm
node_modules

# Optional eslint cache
.eslintcache
*lintrc.json
# Azure Functions artifacts
bin
obj
appsettings.json

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# ignore local.settings.json if it contains your own credentials
# local.settings.json

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
# misc
.DS_Store
.deployment
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# build
/dist

# Stores VSCode user configurations
.vscode
# Azurite emulator
_storage_emulator

# yarn v2
# Local data
.localConfigs
.notification.localstore.json

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
# production
/build
118 changes: 70 additions & 48 deletions Samples/office-keyboard-shortcuts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ description: "This sample shows how to add keyboard shortcuts to your Office Add

## Summary

This sample shows how to create custom keyboard shortcuts for an Office Add-in. Keyboard shortcuts let power users quickly use your add-in's features and give accessibility options to avoid using a mouse. In this sample, the following shortcuts are configured.
This sample shows how to create custom keyboard shortcuts for an Office Add-in. Keyboard shortcuts let power users quickly use your add-in's features and give accessibility options to avoid using a mouse. In this sample, the following shortcuts are configured for each supported platform.

- <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Up arrow key</kbd>: Opens the add-in's task pane.
- <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Down arrow key</kbd>: Hides the add-in's task pane.
- <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Q</kbd>: Performs an action that's specific to the current Office host.
- **Excel**: Cycles through colors in the currently selected cell.
- **Word**: Adds text to the document.
| Action | Windows | Mac | Web |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reordering so web is first...

Suggested change
| Action | Windows | Mac | Web |
| Action | Web | Windows | Mac |

| ----- | ----- | ----- | ----- |
| Open the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Up arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Up arrow key</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>1</kbd> |
| Hide the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Down arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Down arrow key</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>2</kbd> |
| Perform an action that's specific to the current Office host<br>- **Excel**: Cycle through colors in the currently selected cell<br>- **Word**: Add text to the document | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Q</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Q</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>3</kbd> |
Comment on lines +26 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| Open the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Up arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Up arrow key</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>1</kbd> |
| Hide the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Down arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Down arrow key</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>2</kbd> |
| Perform an action that's specific to the current Office host<br>- **Excel**: Cycle through colors in the currently selected cell<br>- **Word**: Add text to the document | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Q</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Q</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>3</kbd> |
| Open the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>1</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Up arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Up arrow key</kbd> |
| Hide the add-in's task pane | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>2</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Down arrow key</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Down arrow key</kbd> |
| Perform an action that's specific to the current Office host<ul><li>**Excel**: Cycle through colors in the currently selected cell</li><li>**Word**: Add text to the document</li></ul> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>3</kbd> | <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Q</kbd> | <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>Q</kbd> |


Keyboard shortcuts can be used to achieve any action within the add-in runtime.

Expand All @@ -41,9 +41,6 @@ Keyboard shortcuts can be used to achieve any action within the add-in runtime.
- Office on the web
- Excel
- Word

> **Note**: The keyboard shortcut feature is currently being rolled out to Word on the web. If you test the feature in Word on the web at this time, the shortcuts may not work if they're activated from within the add-in's task pane. We recommend to periodically check [Keyboard Shortcuts requirement sets](https://learn.microsoft.com/javascript/api/requirement-sets/common/keyboard-shortcuts-requirement-sets) to find out when the feature is fully supported.

- Office on Windows
- Excel: Version 2111 (Build 14701.10000)
- Word: Version 2408 (Build 17928.20114)
Expand All @@ -65,78 +62,101 @@ Keyboard shortcuts can be used to achieve any action within the add-in runtime.

| Version | Date | Comments |
| ------- | ---- | -------- |
| 1.0 | 11-5-2020 | Initial release |
| 1.0 | November 5, 2020 | Initial release |
| 1.1 | May 11, 2021 | Removed yo office and modified to be GitHub hosted |
| 2.0 | September 27, 2024 | Added support for Word |
| 2.1 | December 5, 2024 | Updated keyboard shortcuts |
| 2.2 | July 29, 2025 | Added support for the unified manifest for Microsoft 365 and updated support in Word on the web |

## Disclaimer

**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**

## Run the sample
## Choose a manifest type

### Run the sample from GitHub
By default, the sample uses an add-in only manifest. However, you can switch the project between the add-in only manifest and the unified manifest for Microsoft 365. For more information about the differences between them, see [Office Add-ins manifest](https://learn.microsoft.com/office/dev/add-ins/develop/add-in-manifests). To continue with the add-in only manifest, skip ahead to the [Run the sample](#run-the-sample) section.

Run this sample in Excel or Word. The add-in web files are served from this repository on GitHub.
### To switch to the unified manifest for Microsoft 365

1. Download the **manifest.xml** file from this sample to a folder on your computer.
1. Sideload the manifest file in Excel or Word. The sideloading process varies depending on your platform.
Copy all the files from the **manifest-configurations/unified** subfolder to the sample's root folder, replacing any existing files that have the same names. We recommend that you delete the **manifest.xml** and **manifest-localhost.xml** files from the root folder, so only files needed for the unified manifest are present. Then, [run the sample](#run-the-sample).

- **Office on the web**: [Manually sideload an add-in to Office on the web](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-office-add-ins-for-testing#manually-sideload-an-add-in-to-office-on-the-web)
- **Office on Windows**: [Sideload Office Add-ins for testing from a network share](https://learn.microsoft.com/office/dev/add-ins/testing/create-a-network-shared-folder-catalog-for-task-pane-and-content-add-ins)
- **Office on Mac**: [Sideload Office Add-ins on Mac for testing](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-an-office-add-in-on-mac)
1. Verify that the add-in loaded successfully. You'll see a **Keyboard shortcuts** button on the **Home** tab of the ribbon.
1. Test the sample by following the steps in [Try it out](#try-it-out).
### To switch back to the add-in only manifest

### Run the sample from localhost
To switch back to the add-in only manifest, copy the files from the **manifest-configurations/add-in-only** subfolder to the sample's root folder. We recommend that you delete the **manifest.json** file from the root folder.

If you prefer to host the web server for the sample on your computer, follow these steps.
## Run the sample

1. Install a recent version of [npm](https://www.npmjs.com/get-npm) and [Node.js](https://nodejs.org/) on your computer. To verify if you've already installed these tools, run the commands `node -v` and `npm -v` in your terminal.
1. You need http-server to run the local web server. If you haven't installed this yet, you can do this with the following command.
Run this sample with the [add-in only manifest](#run-with-the-add-in-only-manifest) or [unified manifest for Microsoft 365](#run-with-the-unified-manifest-for-microsoft-365). Use one of the following add-in file hosting options.

```console
npm install --global http-server
```
### Run with the unified manifest for Microsoft 365

1. You need Office-Addin-dev-certs to generate self-signed certificates to run the local web server. If you haven't installed this yet, you can do this with the following command.
1. Clone or download this repository.
1. From a command prompt, go to the root of the project folder **/samples/office-keyboard-shortcuts**.
1. Run `npm install`.
1. Run the applicable command for your Office application.

```console
npm install --global office-addin-dev-certs
```
- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`
Comment on lines +98 to +99
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is indented enough... The rest of the list shouldn't restart numbering

Suggested change
- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`
- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`


1. Clone or download this sample to a folder on your computer, then go to that folder in a console or terminal window.
1. Run the following command to generate a self-signed certificate to use for the web server.
This starts the web server on localhost and sideloads the **manifest.json** file.

1. Verify that the add-in loaded successfully. You'll see a **Keyboard shortcuts** button on the **Home** tab of the ribbon.
1. Follow the steps in [Try it out](#try-it-out) to test the sample.
1. To stop the web server and uninstall the add-in, run the following command.

```console
npx office-addin-dev-certs install
```console
npm stop
```

This command will display the folder location where it generated the certificate files.
### Run with the add-in only manifest

1. Go to the folder location where the certificate files were generated, then copy the **localhost.crt** and **localhost.key** files to the cloned or downloaded sample folder.
1. Run the following command.
To run the sample using the add-in only manifest, you can choose to host the web server on [GitHub](#use-github-as-the-web-host) or (localhost)[#use-localhost].

```console
http-server -S -C localhost.crt -K localhost.key --cors . -p 3000
```
#### Use GitHub as the web host

The http-server will run and host the current folder's files on localhost:3000.
The quickest way to run the sample is to use GitHub as the web host. However, you can't debug or change the source code. The add-in web files are served from this GitHub repository.

1. Sideload the **manifest-localhost.xml** file in Excel or Word. The sideloading process varies depending on your platform.
1. Download the **manifest.xml** file from this sample to a folder on your computer.
1. Sideload the manifest file in Excel or Word. The sideloading process varies depending on your platform.

- **Office on the web**: [Manually sideload an add-in to Office on the web](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-office-add-ins-for-testing#manually-sideload-an-add-in-to-office-on-the-web)
- **Office on Windows**: [Sideload Office Add-ins for testing from a network share](https://learn.microsoft.com/office/dev/add-ins/testing/create-a-network-shared-folder-catalog-for-task-pane-and-content-add-ins)
- **Office on Mac**: [Sideload Office Add-ins on Mac for testing](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-an-office-add-in-on-mac)
1. Verify that the add-in loaded successfully. You'll see a **Keyboard shortcuts** button on the **Home** tab of the ribbon.
1. Test the sample by following the steps in [Try it out](#try-it-out).
1. Follow the steps in [Try it out](#try-it-out) to test the sample.
1. To uninstall the add-in, follow the instructions for the applicable platform.

- [Office on the web](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-office-add-ins-for-testing#remove-a-sideloaded-add-in)
- [Office on Windows](https://learn.microsoft.com/office/dev/add-ins/testing/create-a-network-shared-folder-catalog-for-task-pane-and-content-add-ins#remove-a-sideloaded-add-in)
- [Office on Mac](https://learn.microsoft.com/office/dev/add-ins/testing/sideload-an-office-add-in-on-mac#remove-a-sideloaded-add-in)

#### Use localhost

To host the web server on localhost:

1. Clone or download this repository.
1. From a command prompt, go to the root of the project folder **/samples/office-keyboard-shortcuts**.
1. Run `npm install`.
1. Run the applicable command for your Office application.

- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`
Comment on lines +142 to +143
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is indented enough...

Suggested change
- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`
- **Excel**: `npm run start:desktop:excel`
- **Word**: `npm run start:desktop:word`


This starts the web server on localhost and sideloads the **manifest-localhost.xml** file.

1. Verify that the add-in loaded successfully. You'll see a **Keyboard shortcuts** button on the **Home** tab of the ribbon.
1. Follow the steps in [Try it out](#try-it-out) to test the sample.
1. To stop the web server and uninstall the add-in, run the following command.

```console
npm stop
```

## Try it out

Once the add-in is loaded, try out its functionality.

1. Press <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Up arrow key</kbd> on your keyboard to open the add-in's task pane.
1. Press the [applicable shortcut](#summary) on your keyboard to open the add-in's task pane.

> [!NOTE]
> If the keyboard shortcut is already in use in Excel or Word, a dialog will be shown so that you can select which action you'd like to map to the shortcut. Once you select an action, you can change your preference by invoking the **Reset Office Add-in Shortcut Preferences** command from the search field.
Comment on lines 161 to 162
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is indented enough... you should also indent the rest of the note lines (i.e., >)

Suggested change
> [!NOTE]
> If the keyboard shortcut is already in use in Excel or Word, a dialog will be shown so that you can select which action you'd like to map to the shortcut. Once you select an action, you can change your preference by invoking the **Reset Office Add-in Shortcut Preferences** command from the search field.
> [!NOTE]
> If the keyboard shortcut is already in use in Excel or Word, a dialog will be shown so that you can select which action you'd like to map to the shortcut. Once you select an action, you can change your preference by invoking the **Reset Office Add-in Shortcut Preferences** command from the search field.

Expand All @@ -149,9 +169,11 @@ Once the add-in is loaded, try out its functionality.

The custom keyboard shortcuts implemented in this sample rely on the following components.

- The add-in manifest (**manifest.xml**) is configured to use a shared runtime. For guidance on how to implement a shared runtime in your add-in, see [Configure your Office Add-in to use a shared runtime](https://learn.microsoft.com/office/dev/add-ins/develop/configure-your-add-in-to-use-a-shared-runtime).
- A shortcuts JSON file (**shortcuts.json**) is included in the sample to define the add-in's actions and their keyboard shortcuts. For guidance on how to construct the JSON file, see the [JSON file schema](https://developer.microsoft.com/json-schemas/office-js/extended-manifest.schema.json).
- The custom actions defined in the JSON file are then mapped to their specific JavaScript functions (**taskpane.js**) using the [Office.actions.associate](https://learn.microsoft.com/javascript/api/office/office.actions#office-office-actions-associate-member(1)) method.
- The add-in manifest is configured to use a shared runtime. For guidance on how to implement a shared runtime in your add-in, see [Configure your Office Add-in to use a shared runtime](https://learn.microsoft.com/office/dev/add-ins/develop/configure-your-add-in-to-use-a-shared-runtime).
- The method to define an add-in's actions and their keyboard shortcuts differs depending on the type of manifest your add-in uses.
- **Unified manifest for Microsoft 365**: The actions and keyboard shortcuts are defined in the ["extensions.keyboardShortcuts.shortcuts"](https://learn.microsoft.com/microsoft-365/extensibility/schema/extension-shortcut?view=m365-app-prev&preserve-view=true) array of the **manifest.json** file.
- **Add-in only manifest**: The actions and keyboard shortcuts are defined in a shortcuts JSON file (**shortcuts.json**). For guidance on how to construct the JSON file, see the [JSON file schema](https://developer.microsoft.com/json-schemas/office-js/extended-manifest.schema.json).
- The custom actions defined are then mapped to their specific JavaScript functions (**taskpane.js**) using the [Office.actions.associate](https://learn.microsoft.com/javascript/api/office/office.actions#office-office-actions-associate-member(1)) method.

To learn more about each component, see [Add custom keyboard shortcuts to your Office Add-ins](https://learn.microsoft.com/office/dev/add-ins/design/keyboard-shortcuts).

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Samples/office-keyboard-shortcuts/assets/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Samples/office-keyboard-shortcuts/assets/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"creationDateTime": "2020-11-05",
"updateDateTime": "2024-09-27",
"products": [
"Office"
"Office",
"Teams",
"TeamsToolkit"
],
"metadata": [
{
Expand Down
15 changes: 15 additions & 0 deletions Samples/office-keyboard-shortcuts/env/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file includes environment variables that will be committed to git by default.

# Built-in environment variables
TEAMSFX_ENV=dev
APP_NAME_SUFFIX=dev

# Updating AZURE_SUBSCRIPTION_ID or AZURE_RESOURCE_GROUP_NAME after provision may also require an update to RESOURCE_SUFFIX, because some services require a globally unique name across subscriptions/resource groups.
AZURE_SUBSCRIPTION_ID=
AZURE_RESOURCE_GROUP_NAME=
RESOURCE_SUFFIX=

# Generated during provision, you can also add your own variables.
AZURE_STATIC_WEB_APPS_RESOURCE_ID=
ADDIN_DOMAIN=
ADDIN_ENDPOINT=
25 changes: 25 additions & 0 deletions Samples/office-keyboard-shortcuts/infra/azure.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@maxLength(20)
@minLength(4)
param resourceBaseName string
param staticWebAppSku string

param staticWebAppName string = resourceBaseName

// Azure Static Web Apps that hosts your static web site
resource swa 'Microsoft.Web/staticSites@2022-09-01' = {
name: staticWebAppName
// SWA do not need location setting
location: 'centralus'
sku: {
name: staticWebAppSku
tier: staticWebAppSku
}
properties: {}
}

var siteDomain = swa.properties.defaultHostname

// The output will be persisted in .env.{envName}. Visit https://aka.ms/teamsfx-actions/arm-deploy for more details.
output AZURE_STATIC_WEB_APPS_RESOURCE_ID string = swa.id
output ADDIN_DOMAIN string = siteDomain
output ADDIN_ENDPOINT string = 'https://${siteDomain}'
12 changes: 12 additions & 0 deletions Samples/office-keyboard-shortcuts/infra/azure.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourceBaseName": {
"value": "tab${{RESOURCE_SUFFIX}}"
},
"staticWebAppSku": {
"value": "Free"
}
}
}
Loading