Anatomy of apps for Office

We started this blog with a couple of posts that introduced the new Office cloud app model and the principles behind it: web standards, simplicity, security and performance, consistency, and flexibility to developers. Brian Jones already talked about our background, and as Howard Crow comments in his post, the move to the cloud needed a new architecture for the next generation of apps. We took on this challenge with the goal of combining the power of two big worlds: the web and Office. With this, we wanted to make it easier for millions of developers around the world to provide new and exciting web-powered solutions for hundreds of millions of Office users. In this post I’ll drill down into apps for Office, what they are, their structural components and how end users can experience and consume them through the public Office store or private corporate environments. I’m Rolando Jimenez and I’m the Lead Program Manager for apps for Office. I’ve been working in the custom solutions space for a few years now. I’m excited to finally be able to share the new app model in Office 2013 Preview and the rationale behind some of our key design goals and decisions. I expect this to be the beginning of a rich dialog into more specific topics.

Anatomy of an app for Office

Let’s dive into apps for Office! Because we are in a developer blog, I’ll start with the development perspective. One of our key goals was to make development of the next generation of apps for Office as simple as possible. Our mindset is: “If you can create a webpage, you can create an app for Office”. I believe we nailed it, but of course the final word is yours, so read on and share your thoughts!

Let’s start with the basic anatomy of an app for Office. From a development perspective, an app for Office is essentially a web page integrated into Office as custom content, very similar to how iFrames integrate with other pages on the web. There are just a couple of key differences between a regular web page and an app for Office. The first one is a companion “app manifest” which is a very lightweight XML file that describes how the web page integrates into Office. The second is the ability for the web page to interact with Office content by including a standard script tag referencing our Office JavaScript library (for example, <script src="Office.js"></script>). So, in its most basic form, an app for Office is a webpage plus an xml manifest file.

Webpage + manifest, now what?

After you have a manifest and web page for your app, what do you do with them? We know developers, end users, and IT admins want app discovery and the app lifecycle to be easy, lightweight and secure. Our approach to this is simple. The webpage can be published to any web server using standard methods, and app manifests are published to an app catalog. An app catalog is simply a server that stores a collection of app manifests and controls user access. With app catalogs, new apps can be published pretty easily, and admins have the ability to monitor and control apps from a central location. To cater to different scenarios, Office 2013 Preview supports app catalog options:

  • The public Office Store is a global app catalog hosted and managed by Microsoft that enables developers to reach consumer and corporate users around the world with free or paid apps. (Stay tuned to this blog for a post from Vivek Narasimhan focused on the Office Store.)
  • An app catalog based on SharePoint for private corporate deployment of task pane and content apps. SharePoint 2013 Preview supports app catalogs by default.
  • An app catalog based on Exchange for mail apps.
  • A lightweight shared folder option for development or small group setups, which allows a computer on your local network to share a folder containing app manifest (.xml) files and act as an app catalog.

Office applications know how to connect to all these catalog types and surface apps to end users. The screenshot below shows how apps surface to users in Word 2013 Preview. A new Apps for Office button on the Insert tab of the ribbon brings a dialog that shows all available apps.

I get the technical basics, but how do apps look to end users?

In Office 2013 Preview, apps can surface to end users as three different types. Each app type determines the "UI shape" of the app and its Office behavior.

Content apps

With content apps, we wanted to bring the ability to extend documents with rich custom content. This is something that is hard to do with existing technologies today and content apps make it much easier. Users can insert content apps into a document and they look and behave just like charts
or pictures. In the app framework, we implemented the low-level support to enable apps to be anchored to a specific location, printed, moved, sized, copy/pasted, and so on. This way, you can focus on the content and be confident that it will blend nicely into the Office user interface. Content apps are great as interactive data visualizations, or dynamic/rich content extensions like video or image slide shows. In Office 2013 Preview, content apps are supported in Excel and Excel Web App. The below screenshot contains a content app: the Bing Map.

Task pane apps

Just like content apps, the user inserts task pane apps into the document, and they are saved with it so that the next time someone opens that document she will see the app. But, with task pane apps we wanted to enable a different UI pattern. Instead of being anchored to a specific location, task pane apps show up side-by-side with Office documents—enabling the user to keep the app in view at all times while reading or authoring the document. This makes task pane apps very well suited for presenting contextual content or providing reading and authoring assistance powered by external services. In Office 2013 Preview, task pane apps are supported in Excel, Word, and Project. Below is an example of a task pane app, looking up the latest Bing News right from Word.

Mail apps

We focused on making sure mail apps integrated seamlessly into the common mail and calendar reading patterns supported by Outlook and Outlook Web App. In contrast with content and task pane apps, mail apps are not "insertable." Instead, developers can specify when an app should appear, or activates, in the app bar by writing declarative rules in the manifest. Due to this, apps only appear when they have information or actions that are contextually relevant to the current message or appointment to show. As a result, when reading an email message or appointment, the user will see relevant mail apps in the app bar. Clicking on the app's name activates it inside a horizontal pane. In Office 2013 Preview, mail apps are supported in Outlook and the Outlook Web App. Mail apps also require Exchange Server 2013.

In the following example, you receive an email message that has an address in it. The Bing Map app will automatically appear because it's been set to trigger off of addresses. Clicking on the Bing Map app renders the address in the map.

I’m a developer, show me the Hello World!

Let’s take the above concepts and build the “Hello World” app for Office. Let’s start with a web page with the following HTML:

Nothing sophisticated here, a very simple HTML page is all we need for our Hello World. You can create it with your favorite text or HTML editor and save it to any web server. All you need is to make it accessible over HTTP. Notice the script include for the Office.js library. It holds the key to bridging the web and Office through the new Office JavaScript API, which we'll discuss a bit later.

Now we need the app manifest. The app manifest, as I said before, is a very lightweight XML file. Here's a full sample of the typical manifest you'll need for your apps:

As you can see, along with general attributes like Id, name, version, and description, the manifest specifies three key aspects of how the webpage integrates into Office: 1) the webpage's URL, 2) the app type and capabilities, and 3) the permissions the app will have on Office content.

You can also author the app manifest with your favorite text or XML editor. After you have the app manifest, all you need to do is save it to an app catalog. For our Hello World example, you can save it to a file system folder that you can then share on the network and configure as an app catalog. For example, \\mycomputer\ mysharefolder.

The screenshot below shows a file share catalog configured in Word via the File->Options->Trust Center->Trust Center Settings->Manage App Catalogs option.

That's it, you now have your first app for Office! The result after inserting it via the Insert->Apps for Office ribbon command, should look like this:

Ok, I get the "Hello World"—what about "Real World" apps?

At this point, you are probably wondering how rich can your app's code and logic be? For the app's code, just think of it as any other web project. You can host it in any standard web server and implement server-side logic in the language and platform of your choice (for example, Windows Azure + ASP.NET MVC or Apache + PHP), connect to data and services on the Internet and intranet, use HTML 5, JavaScript, and CSS for your client-side logic, and, of course, use any of the thousands of available JavaScript libraries and frameworks like JQuery, Backbone, Node, Express, YUI, and many, many more.

We expect a lot of apps to capitalize on the power of new or existing Internet, intranet, or cloud Web Services, where a lot of the value comes from the server/service, with the client-side providing a loosely coupled user interface, lightweight business logic through HTML, CSS, and JavaScript,
and integration into Office content through the Office JavaScript API.

The image below shows the canonical architecture of a "real-world" app for Office.

The Office JavaScript API

As you can see, we can build a very comprehensive web project into our app for Office, but if we don't use the Office JavaScript API (supported by the Office.js library) to interact with Office content, we would be missing the point. The Office JavaScript API is the key to capitalizing on the power of integrating the web into Office. It enables you to achieve really interesting and valuable scenarios to delight users. Because of its relevance, I want to share some of the key design goals and capabilities of the API:

  • Compatibility: Apps must work seamlessly across Office versions so we designed the API to encapsulate version specific details.
  • Symmetry: A key design goal of apps for Office is consistency. The API is designed to abstract away the technical differences between different flavors of an Office application, allowing developers to target all of them with a single code base. Specifically, in Office 2013 Preview we focused on symmetry between the Office applications and the Office Web Applications. You will notice that a lot of the methods of this new API are asynchronous. This is part of the strategy for supporting a symmetric API across client-only and client/server environments where network latencies are unpredictable.
  • An API for Office as a suite: With this new JavaScript API we aim to unify the programming model across Office applications. The goal is to enable developers to program against the Office suite with flexibility to target individual applications if desired. For example, one app can support Word and Excel at the same time.
  • API Capabilities:We builtthe API from the ground up, initially focusing on simplicity and supporting basic capabilities that are common across apps. We believe that very powerful scenarios can be enabled with very simple APIs. Our early adopter partners helped us solidify this belief—they have blown us away with what they were able to build in the first stages of the release, even when we had only an API to get the text from a selection. Just to give you a taste of what the API looks like, I want to touch on some of the main capabilities:
    • Read/write access to the user’s selection: Simple methods allow you to get the current selection as text regardless of whether the user selected a paragraph in Word or a cell in an Excel workbook (for content and task pane apps). The following code shows how to read the current selection:

Office.context.document.getSelectedDataAsync(“text”, {},function (asyncResult) {

var selectedText = asyncResult.value;

}

    • Read/write access to user-defined document regions: Through the concept of bindings, apps can read, write, and get selection events and data changed events over specific regions of the document (for content and task pane apps). The following code establishes a binding to the current selection and then reads its contents:

Office.context.document.bindings.addFromSelectionAsync(“text”, { id: 'myBinding' });

//later, read:

myBinding.getDataAsync(function (asyncResult) {

        var contents = asyncResult.value;

    }

});

    • App state persistence: Apps can persist settings and custom properties into the documents they are inserted into (for content and task pane apps). For example, saving a custom setting can be done by calling the following method:

Office.context.document.settings.set('mySetting', 'mySetting value');

    • Access to custom XML parts : In Word 2013 Preview, apps have access to custom XML parts, which enable XML-driven manipulation of the contents in a Word document.

    • Access to item properties: For email and calendar (and therefore mail apps), the API provides access to selected built-in properties and custom properties.

For the full details about the API supported in Office 2013 Preview, check out the reference documentation.

All this is great, but what about development tools?

We designed apps for Office so that they can be built with a broad range of tools and development environments. You can build simple apps with just a text editor. In fact, many of the first internal samples we created were built with Notepad. For more sophisticated apps, you may want to use a more robust web development environment. Because it all works with web standards, you can choose your favorite from the vendor of your choice, all you need is the ability to author web projects. Of course, we expect Visual Studio to be the premier experience and I'm really proud of the work our friends in the Visual Studio team are doing to support development of apps for Office. I won't cover many details here, but I do want to mention that the previews of the Microsoft Office Developer Tools for Visual Studio 2012 and "Napa" Office 365 Development Tools are now available. The latter is a brand new 100% browser-based development environment that enables you to build apps for Office in minutes, without installing anything on your machine. For more details, check out this post from S. Somasegar, corporate vice president of the Microsoft Developer Division.

I built my app, how will users get it?

We talked about how app catalogs provide a centralized solution for end users to get apps and how app manifests are at the core of app deployment. Users can insert apps in Word, Excel, and Project or get them contextually in Outlook. Also, when users share documents that contain apps,
the recipients of those documents automatically get the app too. This works because, when an app is inserted into a document, a reference to its manifest is stored in the document. This reference contains just the app Id and the URL to the app catalog that stores the app manifest.

To summarize, reaching end users is simple:

  1. Upload the manifest to the desired catalog (Office Store, SharePoint, Exchange, or File Share).

  2. Deploy the web project to the web server of your choice.

  3. When users insert apps inside their Office applications, the apps automatically appear in the Office insertion UI.

  4. When users share documents, recipients automatically get included apps from the corresponding app catalog.

  5. Office application start apps transparently to the user by retrieving the app manifest from the corresponding app catalog and loading its main webpage from the source location URL specified in it (for example, the web server location from point #2 above).

Call to action

Hopefully at this point you share our excitement about the potential of apps for Office and are familiar with the core concepts to develop and deploy them. Here’s my recommendation on what to do next to learn more:

  1. Sign up for a free developer site at Office 365. This is by far the easiest way to get started. It gets you the full Office 365 suite with SharePoint, Lync, Exchange, and Office, and our new browser-based app development tools, in just minutes. For more details about Office 365 developer accounts check out the article: Sign up for and Office 365 Developer site.
  2. After you have your developer site, navigate to it and install the “Napa” Office 365 Development Tools by clicking on Get tools to build apps on your home page.
  3. Then, launch the “Napa” Office 365 Development Tools from your dev site by clicking the corresponding link (under Recent) on the left navigation bar of your developer site. This launches you directly into a browser development environment where you can build and run your first app for Office in minutes without needing to install anything on your machine!

Hopefully, this is just the beginning of an exciting dialog about apps for Office. I would love to hear your comments and questions!

- Rolando