Office Add-in Samples

repository·main·Indexed 21 days ago

https://github.com/officedev/office-add-in-samples

A comprehensive collection of code samples for developing Office Add-ins across Excel, Word, PowerPoint, and Outlook. Includes resources for basic task panes, advanced SSO authentication, Blazor WebAssembly integrations, and detailed implementations for Excel custom functions, such as Azure Function integration and the Custom Function Batching pattern.

Tokens
132.5K
Snippets
280
Records
598
Agent score
74%

What's inside office-add-in-samples

  1. Overview of the Office Add-in Microsoft Graph React sample

    main

    This sample demonstrates how to build a single-page application (SPA) Office Add-in with no backend that connects to Microsoft Graph. It uses React, MSAL.js, and Office.js to perform the following workflow:

    1. Connects to Microsoft Graph using the OAuth 2.0 Auth Code Flow with PKCE.
    2. Uses the MSAL.js library for authentication.
    3. Accesses OneDrive for Business via Microsoft Graph REST APIs to find the first three workbooks.
    4. Fetches filenames from those workbooks.
    5. Inserts the filenames into an Office document using Office.js.

    This sample is specifically designed for Excel on Windows (one-time purchase and subscription).

  2. Overview of the Office 365 Outlook MVC Add-in template

    main

    This template is designed to allow the development of Office 365 Outlook add-ins using the ASP.NET MVC framework. Using MVC provides a structured way to integrate and consume resources such as:

    • Microsoft Graph
    • Other web services
    • Databases

    Warning: This project is ARCHIVED and no longer actively maintained. It may contain security vulnerabilities. It is not recommended for use as a starting point for production add-ins. For production development, use the Visual Studio Office/SharePoint development workload or the Yeoman generator for Office Add-ins.

  3. Overview of Office Add-in ASP.NET SSO Sample

    main

    This sample demonstrates an Office Add-in that implements legacy Single Sign-on (SSO) using the getAccessToken API from Office.js. It allows the add-in to access Microsoft Graph data (specifically OneDrive files) on behalf of the user. The solution is built using ASP.NET Core and the Microsoft Authentication Library (MSAL) for .NET.

    Important Security Note: This sample uses legacy SSO. For modern authentication across a wider range of platforms, Microsoft recommends using the Microsoft Authentication Library (MSAL) with nested app authentication (NAA).

  4. Overview of the Word Task Pane Add-in Tutorial Sample

    main

    This sample is a completed version of the step-by-step Tutorial: Create a Word task pane add-in. It was built using the Yeoman generator for Office Add-ins and serves as a reference for exploring completed code or debugging issues encountered during the tutorial.

    Key Features

    • Document Manipulation: Inserts and replaces text ranges, paragraphs, images, HTML, tables, and content controls.
    • Formatting: Demonstrates how to format text within a Word document.
    • Content Management: Shows how to manage document content using content controls.

    Supported Platforms

    • Word on Windows
    • Word on Mac
    • Word on the web
  5. Overview of Office Add-in Microsoft Graph ASP.NET Sample

    main

    This sample demonstrates how to create an Office Add-in that connects to Microsoft Graph to retrieve data from OneDrive for Business. Specifically, it searches for the first three workbooks stored in OneDrive for Business, retrieves their filenames, and uses Office.js to insert those names into an Office document.

    Key Features:

    • Connects an Office Add-in to Microsoft Graph.
    • Implements the OAuth 2.0 authorization framework using the MSAL.NET library.
    • Uses the OneDrive REST API via Microsoft Graph.
    • Displays dialogs using the Office UI namespace.
    • Built using ASP.NET MVC, MSAL 3.x.x for .NET, and Office.js.
    • Utilizes Office Add-in commands.
  6. Overview of Outlook Add-in with Microsoft Graph and MSAL

    main

    This sample demonstrates how to create a Microsoft Outlook add-in that connects to Microsoft Graph to retrieve data. Specifically, it searches for the first three Excel workbooks stored in a user's OneDrive for Business, retrieves their filenames, and inserts them into a new Outlook message composition form.

    Key capabilities demonstrated:

    • Connecting to Microsoft Graph from an Office add-in.
    • Implementing the OAuth 2.0 authorization framework using the MSAL .NET library.
    • Using Microsoft Graph REST APIs for OneDrive and Excel.
    • Displaying dialogs using the Office UI namespace.
    • Building the add-in using ASP.NET MVC, MSAL 3.x.x for .NET, and Office.js.
  7. Overview of the Outlook SSO Sample Add-in

    main

    This sample is an Outlook add-in that demonstrates how to use Office Single Sign-On (SSO) to access Microsoft Graph data. Specifically, it allows users to save email attachments directly to their OneDrive.

    Key technical concepts demonstrated:

    • SSO Access Tokens: Using Office's SSO feature to call Microsoft Graph API without user prompts.
    • MSAL Fallback: Using the Microsoft Authentication Library (MSAL) to authenticate via OneDrive if the SSO token is unavailable.
    • Microsoft Graph API: Creating files in OneDrive.
    • On-Behalf-Of (OBO) Flow: Implementing a WebAPI that exchanges a user's SSO access token for a new access token with permissions for Microsoft Graph and OneDrive using the OAuth 2.0 On-Behalf-Of flow.
  8. Overview of the Word MVC Add-in template

    main

    This template is designed for developing Office 365 Word add-ins using the ASP.NET MVC framework. Using MVC allows the add-in to more easily integrate with server-side resources such as:

    • Microsoft Graph
    • Other web services
    • Databases

    Warning: This project is ARCHIVED and no longer actively maintained. It should not be used as a starting point for production add-ins due to potential security vulnerabilities in the code or its dependencies. For production development, use the Visual Studio Office/SharePoint development workload or the Yeoman generator for Office Add-ins.

  9. Overview of the PowerPoint Task Pane Tutorial Sample

    main

    This sample is a completed version of the step-by-step tutorial: Create a PowerPoint task pane add-in. It is designed for developers who want to explore a finished codebase or debug issues encountered while following the official Microsoft Learn tutorial.

    Key Features

    The sample demonstrates core PowerPoint API interactions, including:

    • Adding a Bing photo of the day to a slide.
    • Adding text to a slide.
    • Retrieving slide metadata.
    • Navigating between slides.

    Compatibility

    • PowerPoint on Windows
    • PowerPoint on Mac
    • PowerPoint on the web
  10. Overview: Get OneDrive data using Microsoft Graph and MSAL.NET

    main

    This sample demonstrates how to build a Microsoft Office Add-in that connects to Microsoft Graph to access OneDrive for Business data. The add-in finds the first three workbooks in OneDrive, retrieves their filenames, and inserts those names into an Office document using Office.js.

    Key Technologies:

    • ASP.NET MVC: Used for the web application hosting the add-in.
    • MSAL.NET (3.x.x): Implements the OAuth 2.0 authorization framework.
    • Microsoft Graph: Used to access OneDrive REST APIs.
    • Office.js: Used to interact with the Office host application (Excel, Word, or PowerPoint).
    • Office UI Namespace: Used to display dialogs.