In the past, the only option an Office programmer had when developing a customized document was to write code against the generic general purpose API provided by the Office application.  As part of VSTO 2.0, we generate a view and data programming model that conform to schemas provided by the developer. 

For example, the developer may have a spreadsheet that contains an ID associated with a customer.  Assume that this ID is located in column A row 2 and the developer wants to set its value to “12345”.  The generic way via the Excel API to talk to that ID is writing code like this:

Workbook(1).Sheets(1).Range("$A$2").Value = 12345

By providing us with a schema for Customer and a mapping from Customer.ID to its actual location in the excel spreadsheet, we can provide two additional generated programming models that give the developer a schema oriented way to talk to the ID in the spreadsheet that are easier to understand and use domain names provided by the developers.

First, we provide a view model.  The view model gives a programmable name to generic API objects and exposes them out as “host controls” that can be easily discovered and programmed against.  The view model way of changing the customer ID looks like this where CustomerIDCell is a “host control”:

CustomerIDCell.Value = 12345

Note that with our view model the developer can also write code to change other attributes of the cell that are not data specific but are view specific.  For example:

CustomerIDCell.Value = 12345
CustomerIDCell.BackColor = Green
CustomerIDCell.Width = 100

Second, we provide a data model.  This model only allows the developer to change the data of interest in the document.  The data model way of changing the customer ID looks like this:

Customer.ID = 12345

The data model acts indirectly against the view via data binding.  All three models—the host API, the view model, and the data model—are loosely coupled together.  This results in three separate loosely coupled programming models:

The Data Model <-connected via databinding to the-> View Model <-connected to the> Host API