Microsoft Office is a staple for many organizations around the world. People use it every day to create documents, spreadsheets and presentations and to manage their email. The applications are full of great features that make using them simple and intuitive, but I am sure there are things you can think of that you would love to be able to do directly in an office application that can’t be done now. Maybe you would like to automatically add content to an email based on content from another system. Maybe you would like to see information from your CRM system about the individual who sent you an email. Or maybe you would like to automatically add html content to an Excel, PowerPoint or Word document. All of these things can be achieved with Microsoft Office add-ins.
What are Office add-ins?
Office add-ins are in the process of being re-branded from the name “Office Apps”. As such, much of the documentation available still refers to them as apps. In concept, office add-ins are simple. They allow developers to extend the functionality of Outlook, Excel, Word, PowerPoint and Project via an API that gives the add-in access to the content of the open item (i.e. document, email, spreadsheet, etc.).
Office add-ins are activated (turned on) based on the context of the application. For example, add-ins may be limited to particular applications or they may be limited to particular circumstances such as only when a user is composing a new email message or only when the content matches a particular regular expression.
Office add-ins can be installed from the Office store or, when being used for purposes specific to a company or individual, they can be installed via a specific url or directly from a manifest file on the local machine.
Anatomy of an Office add-in
Creating an Office add-in
This section will cover a complete example add-in that was developed to help us at Mercury New Media tie our Outlook calendar appointments to specific customers and projects. This serves as a specific example of a real-world (albeit simple) application of Office add-ins. There are so many features available that it would be impossible to show them all, but this should give a good sampling of what can be done.
For this add-in, we will be using hashtags included in the body of an appointment to identify a calendar appointment as being related to a specific client and project. Without this add-in, we would need to either remember the hashtag related to each project we work on or we would need to go look them up each time we wanted to add a tag an appointment. This add-in makes it so we can seamlessly add a hashtag from within Outlook or view the client and project associated with an appointment that was sent to us.
The manifest file
The manifest file is used to show exactly where the add-in can be found as well as when it should activate. You can see in the manifest file shown below how an add-in is defined. The most interesting parts can be found in the FormSettings and RuleCollection elements.
The FormSetting section is used to specify the starting urls for the add-in. In this example, we have two different starting urls. One is used when a calendar item is in edit mode and one is used when it is in read mode. These urls must be publicly accessible pages protected by SSL. It is possible to use single sign on between Office 365 and your application to provide seamless authentication if desired.
The RuleCollection specifies one or more rules for when your add-in should show up. For this example, we want the add-in to display if we are editing an appointment (so that we can add hashtags to that appointment) or if the appointment we are viewing has one or more hashtags included in it. The second rule makes use of a regular expression match to find all hashtags in an appointment. There are also built-in options to recognize addresses, appointment time suggestions and attachments.
The first is Office.initialize, which you can think of as being similar to JQuery’s $(document).ready(). It is used to insure that your add-in does not try to run it’s scripts before the Office application is ready. Anything that is supposed to run when the page loads should be inside the defined Office.initialize function. In our case, we want to load some dropdown options and bind some controls to specific actions.
The other reference to the Office api is when we click the “Add Tag” button to put the selected hashtag into the appointment being created. At this point we use the prependAsync() function to add the hashtag text directly to the body of the appointment.
In the read mode, we want to find all hashtags that were included in the appointment we are viewing so that we can display the projects they are related to. Like the edit mode, we again include all of our setup in the Office.initialize function. The add-in is able to get the hashtags that were included in the appointment by using the getRegExMatches() function and referencing the RegExName given to the hashtag regular expression in the manifest.
Installing the add-in
Once the add-in is completed and published to a publicly available url, installing it to your Office 365 account is pretty straightforward.
- Log in to your Office 365 portal
- Click the “Settings” gear in the upper right-hand corner of the page.
- Click “Manage Apps” (there is that old terminology still hanging around)
- Click the + above the list of installed applications
- Here you can choose to install it from the Office Store, a URL or a file.
- If you are going to install from a URL or file, the link should go directly to the Manifest.xml file.
Once the add-in is installed, you will be able to see it in both the web portal version of the application and the desktop version.
Tools and Resources
- napacloudapp.com is a tool that lets you get started with an Office add-in quickly be generating a starting template.