Excel Add-ins Quick Start

Build your first Excel add-in with this step-by-step guide.

Get Started with Excel Add-ins

Welcome to the quick start guide for developing Office Add-ins! This tutorial will walk you through creating a simple "Hello World" add-in for Excel. By the end of this guide, you'll have a functional add-in that can be sideloaded into Excel.

Prerequisites

Step 1: Set Up Your Development Environment

We'll use the Yeoman generator for Office Add-ins to create our project. This tool scaffolds a basic add-in project with all the necessary files and configurations.

Install the Yeoman Generator

Open your terminal or command prompt and run the following command to install the generator globally:

npm install -g yo generator-office

If you're using Yarn, use:

yarn global add yo generator-office

Step 2: Create Your First Excel Add-in Project

Navigate to the directory where you want to create your project in your terminal and run the generator.

Generate the Project

Run the following command and follow the prompts:

yo office

When prompted:

The generator will create a new folder with your project name and install all the required dependencies. This might take a few minutes.

Step 3: Explore the Project Structure

Navigate into your newly created project directory:

cd MyExcelAddin

Open this folder in your code editor. You'll find a structure like this:


MyExcelAddin/
├── .vscode/
├── images/
├── node_modules/
├── App.js
├── App.html
├── App.css
├── manifest.xml
├── package.json
└── ... (other configuration files)
        

Step 4: Run Your Add-in

Now, let's start the local development server and see our add-in in action.

Start the Development Server

In your terminal, run:

npm start

Or if you're using Yarn:

yarn start

This command will build your add-in and start a local web server. It will also automatically open your add-in in your default Office client (usually Excel). If it doesn't open automatically, follow the instructions that appear in the terminal.

Important: Your add-in runs in a separate pane within Excel. You'll see a task pane appear on the right side of your Excel window.

Step 5: Interact with Your Add-in

The default "Hello World" add-in usually has a button. Click it and observe how it interacts with Excel.

Understanding the Code

Let's look at a simplified example of the interaction in App.js:


// Office JavaScript API helper functions
(function () {
    Office.onReady(function () {
        $(document).ready(function () {
            $('#run').on('click', insertText);
        });
    });

    function insertText() {
        Office.context.document.setSelectedDataAsync("Hello World from your Excel Add-in!");
    }
})();
        

This code snippet:

Step 6: Customize Your Add-in (Optional)

You can modify App.html, App.css, and App.js to change the look and behavior of your add-in.

Example: Changing the Button Text

Open App.html and find the button element:

<button id="run">Run</button>

Change it to:

<button id="run">Insert Greeting</button>

Save the file. The development server should automatically reload, and you'll see the updated button text in Excel.

Next Steps

Congratulations! You've successfully created and run your first Excel add-in. From here, you can:

View More Tutorials