Create Office Web Add-In Project Using Visual Studio

In this article, I would like to share the steps to create Office web add-in project using Visual Studio.

What are Office Web add-ins?

  • Office add-ins are run in Office applications. They can interact with the document and data or email contents.
  • Office Add-ins is a web app, that can be hosted anywhere
  • It only runs on office application and extends the functionality of Office clients, such as Word, Excel, PowerPoint, and Outlook using the web technologies.
  • Office add-ins are run across multiple version of Office,

    • Windows Desktop
    • MAC
    • Office for Online
    • iPad

  • It is used to create custom ribbons, tabs and add-in commands

Office web add-in projects have the manifest.xml and web project.

visual studio

Steps to Create Office web add-in

Follow the below listed steps to create Office web-add-in

Step 1

Open Visual Studio 2015 as administrator (Office dev tool is available by default)

visual studio

Step 2

Then click New Project from Start as shown in below,

visual studio

Step 3

On the pop up screen select “Web add-ins” from Office/SharePoint category

visual studio

Step 4

Then Select the “Word add-in” Project template to create new Office web word add-in project

visual studio

Step 5

Provide the project name for your add-in and select the location where your project has to create and click “OK”,

visual studio

Step 6

Finally, Office web add-in project will be created successfully. As I said already it will have manifest.xml and one web project

visual studio

Manifest.xml - It is used for where the app is located and how the app should appear,

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--Created:ce44715c-8c4e-446b-879c-ea9ebe0f09c8-->  
  3. <OfficeApp   
  4.           xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"   
  5.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  6.           xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"   
  7.           xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"  
  8.           xsi:type="TaskPaneApp">  
  9.   
  10.   <!-- Begin Basic Settings: Add-in metadata, used for all versions of Office unless override provided. -->  
  11.   
  12.   <!-- IMPORTANT! Id must be unique for your add-inif you reuse this manifest ensure that you change this id to a new GUID. -->  
  13.   <Id>0ad9638f-3e8d-43c3-978f-bba11a4389ea</Id>  
  14.   
  15.   <!--Version. Updates from the store only get triggered if there is a version change. -->  
  16.   <Version>1.0.0.0</Version>  
  17.   <ProviderName>[Provider name]</ProviderName>  
  18.   <DefaultLocale>en-US</DefaultLocale>  
  19.   <!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. -->  
  20.   <DisplayName DefaultValue="SampleWordAdd-inTest" />  
  21.   <Description DefaultValue="SampleWordAdd-inTest"/>  
  22.   
  23.   <!-- Icon for your add-in. Used on installation screens and the add-ins dialog. -->  
  24.   <IconUrl DefaultValue="~remoteAppUrl/Images/Button32x32.png" />  
  25.   
  26.   <!-- Domains that will be allowed when navigating. For example, if you use ShowTaskpane and then have an href link, navigation will only be allowed if the domain is on this list. -->  
  27.   <AppDomains>  
  28.     <AppDomain>AppDomain1</AppDomain>  
  29.     <AppDomain>AppDomain2</AppDomain>  
  30.     <AppDomain>AppDomain3</AppDomain>  
  31.   </AppDomains>  
  32.   <!--End Basic Settings. -->  
  33.     
  34.   <!--Begin TaskPane Mode integration. This section is used if there are no VersionOverrides or if the Office client version does not support add-in commands. -->  
  35.   <Hosts>  
  36.     <Host Name="Document" />  
  37.   </Hosts>  
  38.   <DefaultSettings>  
  39.     <SourceLocation DefaultValue="~remoteAppUrl/Home.html" />  
  40.   </DefaultSettings>  
  41.   <!-- End TaskPane Mode integration.  -->  
  42.   
  43.   <Permissions>ReadWriteDocument</Permissions>  
  44.   
  45.   <!-- Begin Add-in Commands Mode integration. -->  
  46.   <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">  
  47.       
  48.     <!-- The Hosts node is required. -->  
  49.     <Hosts>  
  50.       <!-- Each host can have a different set of commands. -->  
  51.       <!-- Excel host is Workbook, Word host is Document, and PowerPoint host is Presentation. -->  
  52.       <!-- Make sure the hosts you override match the hosts declared in the top section of the manifest. -->  
  53.       <Host xsi:type="Document">  
  54.         <!-- Form factor. Currently only DesktopFormFactor is supported. -->  
  55.         <DesktopFormFactor>  
  56.           <!--"This code enables a customizable message to be displayed when the add-in is loaded successfully upon individual install."-->  
  57.           <GetStarted>  
  58.             <!-- Title of the Getting Started callout. resid points to a ShortString resource -->  
  59.             <Title resid="Contoso.GetStarted.Title"/>  
  60.   
  61.             <!-- Description of the Getting Started callout. resid points to a LongString resource -->  
  62.             <Description resid="Contoso.GetStarted.Description"/>  
  63.   
  64.             <!-- Point to a url resource which details how the add-in should be used. -->  
  65.             <LearnMoreUrl resid="Contoso.GetStarted.LearnMoreUrl"/>  
  66.           </GetStarted>  
  67.           <!-- Function file is a HTML page that includes the JavaScript where functions for ExecuteAction will be called.   
  68.             Think of the FunctionFile as the code behind ExecuteFunction. -->  
  69.           <FunctionFile resid="Contoso.DesktopFunctionFile.Url" />  
  70.   
  71.           <!-- PrimaryCommandSurface is the main Office Ribbon. -->  
  72.           <ExtensionPoint xsi:type="PrimaryCommandSurface">  
  73.             <!-- Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab. -->  
  74.             <OfficeTab id="TabHome">  
  75.               <!-- Ensure you provide a unique id for the group. Recommendation for any IDs is to namespace using your company name. -->  
  76.               <Group id="Contoso.Group1">  
  77.                 <!-- Label for your group. resid must point to a ShortString resource. -->  
  78.                 <Label resid="Contoso.Group1Label" />  
  79.                 <!-- Icons. Required sizes 16,32,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX. -->  
  80.                 <!-- Use PNG icons. All URLs on the resources section must use HTTPS. -->  
  81.                 <Icon>  
  82.                   <bt:Image size="16" resid="Contoso.tpicon_16x16" />  
  83.                   <bt:Image size="32" resid="Contoso.tpicon_32x32" />  
  84.                   <bt:Image size="80" resid="Contoso.tpicon_80x80" />  
  85.                 </Icon>  
  86.   
  87.                 <!-- Control. It can be of type "Button" or "Menu". -->  
  88.                 <Control xsi:type="Button" id="Contoso.TaskpaneButton">  
  89.                   <Label resid="Contoso.TaskpaneButton.Label" />  
  90.                   <Supertip>  
  91.                     <!-- ToolTip title. resid must point to a ShortString resource. -->  
  92.                     <Title resid="Contoso.TaskpaneButton.Label" />  
  93.                     <!-- ToolTip description. resid must point to a LongString resource. -->  
  94.                     <Description resid="Contoso.TaskpaneButton.Tooltip" />  
  95.                   </Supertip>  
  96.                   <Icon>  
  97.                     <bt:Image size="16" resid="Contoso.tpicon_16x16" />  
  98.                     <bt:Image size="32" resid="Contoso.tpicon_32x32" />  
  99.                     <bt:Image size="80" resid="Contoso.tpicon_80x80" />  
  100.                   </Icon>  
  101.   
  102.                   <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->  
  103.                   <Action xsi:type="ShowTaskpane">  
  104.                     <TaskpaneId>ButtonId1</TaskpaneId>  
  105.                     <!-- Provide a url resource id for the location that will be displayed on the task pane. -->  
  106.                     <SourceLocation resid="Contoso.Taskpane.Url" />  
  107.                   </Action>  
  108.                 </Control>  
  109.               </Group>  
  110.             </OfficeTab>  
  111.           </ExtensionPoint>  
  112.         </DesktopFormFactor>  
  113.       </Host>  
  114.     </Hosts>  
  115.       
  116.     <!-- You can use resources across hosts and form factors. -->  
  117.     <Resources>  
  118.       <bt:Images>  
  119.         <bt:Image id="Contoso.tpicon_16x16" DefaultValue="~remoteAppUrl/Images/Button16x16.png" />  
  120.         <bt:Image id="Contoso.tpicon_32x32" DefaultValue="~remoteAppUrl/Images/Button32x32.png" />  
  121.         <bt:Image id="Contoso.tpicon_80x80" DefaultValue="~remoteAppUrl/Images/Button80x80.png" />  
  122.       </bt:Images>  
  123.       <bt:Urls>  
  124.         <bt:Url id="Contoso.DesktopFunctionFile.Url" DefaultValue="~remoteAppUrl/Functions/FunctionFile.html" />  
  125.         <bt:Url id="Contoso.Taskpane.Url" DefaultValue="~remoteAppUrl/Home.html" />  
  126.         <bt:Url id="Contoso.GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />  
  127.       </bt:Urls>  
  128.       <!-- ShortStrings max characters==125. -->  
  129.       <bt:ShortStrings>  
  130.         <bt:String id="Contoso.TaskpaneButton.Label" DefaultValue="Show Taskpane" />  
  131.         <bt:String id="Contoso.Group1Label" DefaultValue="Commands Group" />  
  132.         <bt:String id="Contoso.GetStarted.Title" DefaultValue="Get started with your sample add-in!" />  
  133.       </bt:ShortStrings>  
  134.       <!-- LongStrings max characters==250. -->  
  135.       <bt:LongStrings>  
  136.         <bt:String id="Contoso.TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane" />  
  137.         <bt:String id="Contoso.GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started." />  
  138.       </bt:LongStrings>  
  139.     </Resources>  
  140.   </VersionOverrides>  
  141.   <!-- End Add-in Commands Mode integration. -->  
  142.   
  143. </OfficeApp>  

visual studio 

Note

Make sure that Office Word 2016 is installed on your machine to run the project

Step 7

Start your project, and the Office Word client application will open and we can see the command button as shown below,

visual studio

Task pane will be opened when you click on the show task pane button

visual studio

Summary

In this article, we have explored what  Office add-ins are and how to create an Office web add-in project using Visual Studio 2015.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now