Office Add-in code samples
These code samples are written to help you learn how to use various features when developing Office Add-ins.
The following samples show how to build the simplest Office Add-in with only a manifest, HTML web page, and a logo. These components are the fundamental parts of an Office Add-in. For additional getting started information, see our quick starts and tutorials.
- Excel "Hello world" add-in
- Outlook "Hello world" add-in
- PowerPoint "Hello world" add-in
- Word "Hello world" add-in
|Encrypt attachments, process meeting request attendees, and react to appointment date/time changes||Use event-based activation to encrypt attachments when added by the user. Also use event handling for recipients changed in a meeting request, and changes to the start or end date or time in a meeting request.|
|Use Outlook event-based activation to tag external recipients (preview)||Use event-based activation to run an Outlook add-in when the user changes recipients while composing a message. The add-in also uses the
|Use Outlook event-based activation to set the signature||Use event-based activation to run an Outlook add-in when the user creates a new message or appointment. The add-in can respond to events, even when the task pane is not open. It also uses the
|Open in Teams||Create a new Excel spreadsheet in Microsoft Teams containing data you define.|
|Insert an external Excel file and populate it with JSON data||Insert an existing template from an external Excel file into the currently open Excel workbook. Then, populate the template with data from a JSON web service.|
|Create custom contextual tabs on the ribbon||Create a custom contextual tab on the ribbon in the Office UI. The sample creates a table, and when the user moves the focus inside the table, the custom tab is displayed. When the user moves outside the table, the custom tab is hidden.|
|Use keyboard shortcuts for Office add-in actions||Set up a basic Excel add-in project that utilizes keyboard shortcuts.|
|Custom function sample using web worker||Use web workers in custom functions to prevent blocking the UI of your Office Add-in.|
|Use storage techniques to access data from an Office Add-in when offline||Implement localStorage to enable limited functionality for your Office Add-in when a user experiences lost connection.|
|Custom function batching pattern||Batch multiple calls into a single call to reduce the number of network calls to a remote service.|
|Share global data with a shared runtime||Set up a basic project that uses the shared runtime to run code for ribbon buttons, task pane, and custom functions in a single browser runtime.|
|Manage ribbon and task pane UI, and run code on doc open||Create contextual ribbon buttons that are enabled based on the state of your add-in.|
Authentication, authorization, and single sign-on (SSO)
|Single Sign-on (SSO) Sample Outlook Add-in||Use Office's SSO feature to give the add-in access to Microsoft Graph data.|
|Get OneDrive data using Microsoft Graph and msal.js in an Office Add-in||Build an Office Add-in, as a single-page application (SPA) with no backend, that connects to Microsoft Graph, and access workbooks stored in OneDrive for Business to update a spreadsheet.|
|Office Add-in auth to Microsoft Graph||Learn how to build a Microsoft Office Add-in that connects to Microsoft Graph, and access workbooks stored in OneDrive for Business to update a spreadsheet.|
|Outlook Add-in auth to Microsoft Graph.||Build an Outlook add-in that connects to Microsoft Graph, and access workbooks stored in OneDrive for Business to compose a new email message.|
|Single Sign-on (SSO) Office Add-in with ASP.NET||Use the
|Single Sign-on (SSO) Office Add-in with Node.js||Use the
|Use a shared library to migrate your Visual Studio Tools for Office add-in to an Office web add-in||Provides a strategy for code reuse when migrating from VSTO Add-ins to Office Add-ins.|
|Integrate an Azure function with your Excel custom function||Integrate Azure functions with custom functions to move to the cloud or integrate additional services.|
|Dynamic DPI code samples||A collection of samples for handling DPI changes in COM, VSTO, and Office Add-ins.|
Join the Microsoft 365 Developer Program. Get a free sandbox, tools, and other resources you need to build solutions for the Microsoft 365 platform.
- Free developer sandbox Get a free, renewable 90-day Microsoft 365 E5 developer subscription.
- Sample data packs Automatically configure your sandbox by installing user data and content to help you build your solutions.
- Access to experts Access community events to learn from Microsoft 365 experts.
- Personalized recommendations Find developer resources quickly from your personalized dashboard.