with TypeScript

Before you read this page you should read using NotePad with TypeScript

Create Project Folder

Open File Explorer and create the (C:\temp\vscode) folder.
Create a new subfolder called "excel-typescript" (C:\temp\vscode\excel-typescript).
Open Visual Studio Code.
Display the Terminal window (View > Terminal).
Change to that folder.

cd C:\temp\vscode 

Install Yeoman

The Yeoman generator is an open source scaffolding tool for creating web applications.
This generator creates a Node.js project.

npm install -g yo   // 3.1.1 
npm install -g generator-office // 1.7.6

check the versions and update if necessary.

yo --version 
npm view generator-office version

Generate Template Files

Run the Yeoman generator to create the project.

yo office 

Choose a project type: Select "Office Add-in Task Pane project".

Choose a script type: Select "TypeScript".
What do you want to name your add-in: Type "Excel-TypeScript".
Choose which office client application you want to target: Select "Excel".
All the necessary files will then be created for you.
Open File Explorer and browse the following folder (C:\temp\vscode\
To open this folder in Visual Studio Code, type "code ."

code . 


<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 

<Id> Unique GUID </Id>
<ProviderName>Better Solutions Limited</ProviderName>
<DisplayName DefaultValue="Excel-TypeScript"/>
<Description DefaultValue="A template to get started."/>
<IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
<SupportUrl DefaultValue="https://www.bettersolutions.com"/>
<Host Name="Workbook"/>
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
<Host xsi:type="Workbook">
<Title resid="GetStarted.Title"/>
<Description resid="GetStarted.Description"/>
<LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
<FunctionFile resid="Commands.Url"/>
<ExtensionPoint xsi:type="PrimaryCommandSurface">
<OfficeTab id="TabHome">
<Group id="CommandsGroup">
<Label resid="CommandsGroup.Label"/>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
<Control xsi:type="Button" id="TaskpaneButton">
<Label resid="TaskpaneButton.Label"/>
<Title resid="TaskpaneButton.Label"/>
<Description resid="TaskpaneButton.Tooltip"/>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
<Action xsi:type="ShowTaskpane">
<SourceLocation resid="Taskpane.Url"/>
<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
<bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
<bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
<bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
<bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/>
<bt:String id="CommandsGroup.Label" DefaultValue="Commands Group"/>
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
<bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully."/>
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/>

package.json file

Expand the Explorer pane on the left hand side.
Expand the project "Excel-TypeScript".
Click on the package.json file.

"name": "office-addin-taskpane-js",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/OfficeDev/Office-Addin-TaskPane-JS.git"
"license": "MIT",
"config": {
"app-to-debug": "excel",
"app-type-to-debug": "desktop",
"dev-server-port": 3000
"scripts": {
"build": "webpack -p --mode production --https false",
"build:dev": "webpack --mode development --https false",
"dev-server": "webpack-dev-server --mode development",
"lint": "office-addin-lint check",
"lint:fix": "office-addin-lint fix",
"prettier": "office-addin-lint prettier",
"start": "office-addin-debugging start manifest.xml",
"start:desktop": "office-addin-debugging start manifest.xml desktop",
"start:web": "office-addin-debugging start manifest.xml web",
"stop": "office-addin-debugging stop manifest.xml",
"validate": "office-addin-manifest validate manifest.xml",
"watch": "webpack --mode development --watch"
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/polyfill": "^7.11.5",
"@babel/preset-env": "^7.11.5",
    "@types/find-process": "1.2.0"
"@types/office-js": "^1.0.108",
"@types/office-runtime": "^1.0.14",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.1.1",
"eslint-config-office-addins": "^1.0.19",
    "find-process": "^1.4.3"
"file-loader": "^4.2.0",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^4.5.0",
"office-addin-cli": "^1.0.13",
"office-addin-debugging": "^3.0.34",
"office-addin-dev-certs": "^1.5.5",
"office-addin-lint": "^1.0.26",
"office-addin-manifest": "^1.5.7",
"office-addin-prettier-config": "^1.0.12",
"source-map-loader": "^0.2.4",
"ts-loader": "^6.2.2",
"typescript": "^4.0.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
"prettier": "office-addin-prettier-config"


const devCerts = require("office-addin-dev-certs"); 
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const fs = require("fs");
const webpack = require("webpack");

const urlDev="https://localhost:3000/";
const urlProd="https://bettersolutions.com/"; // CHANGE THIS TO YOUR PRODUCTION DEPLOYMENT LOCATION

module.exports = async (env, options) => {
  const dev = options.mode === "development";
  const buildType = dev ? "dev" : "prod";
  const config = {
    devtool: "source-map",
    entry: {
      polyfill: "@babel/polyfill",
      taskpane: "./src/taskpane/taskpane.ts",
      commands: "./src/commands/commands.ts"
    resolve: {
      extensions: [".ts", ".tsx", ".html", ".js"]
    module: {
      rules: [
          test: /\.ts$/,
          exclude: /node_modules/,
          use: "babel-loader"
          test: /\.tsx?$/,
          exclude: /node_modules/,
          use: "ts-loader"
          test: /\.html$/,
          exclude: /node_modules/,
          use: "html-loader"
          test: /\.(png|jpg|jpeg|gif)$/,
          loader: "file-loader",
          options: {
            name: '[path][name].[ext]',
    plugins: [
      new CleanWebpackPlugin(),
      new HtmlWebpackPlugin({
        filename: "taskpane.html",
        template: "./src/taskpane/taskpane.html",
        chunks: ["polyfill", "taskpane"]
      new CopyWebpackPlugin({
        patterns: [
          to: "taskpane.css",
          from: "./src/taskpane/taskpane.css"
          to: "[name]." + buildType + ".[ext]",
          from: "manifest*.xml",
          transform(content) {
            if (dev) {
              return content;
            } else {
              return content.toString().replace(new RegExp(urlDev, "g"), urlProd);
      new HtmlWebpackPlugin({
        filename: "commands.html",
        template: "./src/commands/commands.html",
        chunks: ["polyfill", "commands"]
    devServer: {
      headers: {
        "Access-Control-Allow-Origin": "*"
      https: (options.https !== undefined) ? options.https : await devCerts.getHttpsServerOptions(),
      port: process.env.npm_package_config_dev_server_port || 3000

  return config;


This file contains the html code for the task pane.
Expand the "src" folder.
Expand the "taskpane" folder.
Click on the taskpane.html file.

<!DOCTYPE html> 

<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Task Pane Add-in</title>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/9.6.1/css/fabric.min.css"/>
<link href="taskpane.css" rel="stylesheet" type="text/css" />

<body class="ms-font-m ms-welcome ms-Fabric">
<header class="ms-welcome__header ms-bgColor-neutralLighter">
<img width="90" height="90" src="../../assets/logo-filled.png" alt="Contoso" title="Contoso" />
<h1 class="ms-font-su">Welcome</h1>
<section id="sideload-msg" class="ms-welcome__main">
<h2 class="ms-font-xl">Please sideload your add-in to see app body.</h2>
<main id="app-body" class="ms-welcome__main" style="display: none;">
<h2 class="ms-font-xl"> Discover what Office Add-ins can do for you today! </h2>
<ul class="ms-List ms-welcome__features">
<li class="ms-ListItem">
<i class="ms-Icon ms-Icon--Ribbon ms-font-xl"></i>
<span class="ms-font-m">Achieve more with Office integration</span>
<li class="ms-ListItem">
<i class="ms-Icon ms-Icon--Unlock ms-font-xl"></i>
<span class="ms-font-m">Unlock features and functionality</span>
<li class="ms-ListItem">
<i class="ms-Icon ms-Icon--Design ms-font-xl"></i>
<span class="ms-font-m">Create and visualize like a pro</span>
<p class="ms-font-l">Modify the source files, then click <b>Run</b>.</p>
<div role="button" id="run" class="ms-welcome__action ms-Button ms-Button--hero ms-font-xl">
<span class="ms-Button-label">Run</span>


This file contains the typescript that sits behind the html page.

Office.onReady(info => { 
if (info.host === Office.HostType.Excel) {
document.getElementById("sideload-msg").style.display = "none";
document.getElementById("app-body").style.display = "flex";
document.getElementById("run").onclick = run;

export async function run() {
  try {
    await Excel.run(async context => {
       * Insert your Excel code here
      const range = context.workbook.getSelectedRange();

      // Read the range address

      // Update the fill color
      range.format.fill.color = "yellow";

      await context.sync();
      console.log(`The range address was ${range.address}.`);
  } catch (error) {

Other Project Files

The other project files are displayed on this page: Visual Studio Code > Yeoman Generator for reference.

Load the Add-in - Desktop

Execute the following command:

cd C:\temp\vscode\Excel-TypeScript 
npm start

This will start the local web server and open Excel with the add-in loaded.
A small node window will be displayed.
A security warning dialog box will be displayed, asking you to install the certificate. Press Yes.
Select the Home tab and you will see a new group called "Commands Group" on the right hand side.

Highlight a range of cells and press the Run button.

Load the Add-in - Online

Execute the following command:

cd C:\temp\vscode\Excel-TypeScript 
npm start: web

This will start the local web server.
The add-in will not appear automatically and will require side loading.

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext