The API Tutorial for Office teaches you how to get started writing code for an app for Office. The tutorial is an app for Office that runs in Excel or Excel Web App. You can download the app for free from the Office Store, but you can also run it online from the MSDN website. In this post, learn how to get started.

Getting started

The API Tutorial app teaches you how to write code to perform six basic tasks using the JavaScript API for Office. To get started, just open the API Tutorial for Office page on MSDN.

Note: To run the tutorial online, you need to be running at least Internet Explorer 9, Safari 5.0.6, Firefox 5, Chrome 13, or a later version of one of these browsers.

Like all apps for Office hosted on external sites that can read and write to your documents, the first time you run it you need to choose Start:

Figure 1. The New App for Office prompt

Figure 1. The New App for Office prompt

Once you've done that, the API Tutorial app opens its first script sample, which will call the setSelectedDataAsync method to write to the spreadsheet. To run that, first select a cell, and then choose Run Code:

Figure 2. Write "Hello World!" to the spreadsheet

Figure 2. Write "Hello World!" to the spreadsheet

Choose Next Step, and then choose Run Code again to call the getSelectedDataAsync method to read data from the selected cell and display it in notification at the bottom of the app:

Figure 3. Read from the selected cell

Figure 3. Read from the selected cell

Clear the notification, and then choose More Tutorials to access tutorials for all six scripting tasks.

Figure 4. Select a tutorial

Figure 4. Select a tutorial

Learn more about the code

All six tutorials provide brief descriptions of each code example with links to documentation for key members of API used in the example. To read about the code, choose the Description "tab" right above the Code window:

Figure 5. The code description

Figure 5. The code description

Experiment with the code

In each of the tutorials, you can edit the code in the window and click Run Code to try out something different. Here's a simple example of editing the data parameter string passed to the setSelectedData method to change what's written back to the selected cell:

Figure 6. Editing code

Figure 6. Editing code

Because the textarea that contains the code example is fully editable and executing against the JavaScript API for Office library, you can use it as an interactive JavaScript console to try out and play with script that works in the context of Excel and Excel Web App. Try rewriting or extending examples to perform tasks such as:

· Inserting tables with different numbers or rows and columns

· Adding rows or columns to a table after it's been inserted

· Getting data from a selection within a binding.

For more examples and information about how to perform tasks, see Asynchronous programming in app for Office, Reading and writing data to the active selection in a document or spreadsheet, Binding to regions in a document or spreadsheet, and the API reference topics for the JavaScript API for Office. To determine if an API will work in the context of Excel, refer to the "Supported clients" row of the "Requirements" section at the bottom of every API reference topic:

image

Figure 7. Supported clients

jQuery and JavaScript support

Because the API Tutorial app references the jQuery library (version 1.7.1), you can also use jQuery in your script.

When you run the app from the Excel Web App, because script is running in the context of the browser you opened it with, most JavaScript supported by that browser should run as well.

If you have Excel 2013, you can also download the API Tutorial for Office from the Office Store and run it from your local copy of Excel. When you run the app from Excel 2013 or later, it runs in the context of the version of Internet Explorer installed on your computer (which must be IE9 or later), so you can use JavaScript supported by the installed version of IE.

Open the tutorial app project in "Napa"

At the end of each tutorial, if you've signed up for an Office 365 Developer Site with the "Napa" Office 365 Development Tools installed on that site, you can choose the Open in Napa button to open the API Tutorial app project in Napa.

Figure 7. Tutorial App open in Napa

Figure 7. Tutorial App open in Napa

The API Tutorial for Office is a great way to get started learning some basic scripting tasks for apps for Office. To learn more, see Build apps for Office and the Apps for Office and SharePoint Dev Center on MSDN.