Export (0) Print
Expand All

Cached Data in Document-Level Customizations

A primary goal of document-level customizations is to separate data from view in Office documents. Data refers to the information that is stored in the document, including numbers and text. View refers to the user interface and the object model of Microsoft Office Word and Microsoft Office Excel.

Visual Studio separates the data from the view in document-level customizations by enabling data to be embedded as a data island, also called the data cache. You can read or modify the data directly without starting Word or Excel. This is useful when you need to modify data in documents on a server that does not have Microsoft Office installed. Word and Excel are intended for use in client environments; they are not designed to be run on a server.

Applies to: The information in this topic applies to document-level projects for the following applications: Excel 2013 and Excel 2010; Word 2013 and Word 2010. For more information, see Features Available by Office Application and Project Type.

For more information about document-level customizations, see Office Solutions Development Overview and Architecture of Document-Level Customizations.

The data island can contain any object in your solution that meets certain requirements. These objects include DataSet objects, DataTable objects, and any other object that can be serialized by the XmlSerializer class. For more information, see see Caching Data.

To provide the view for the cached data, you can bind Windows Forms controls and host controls on the document to objects in the data island. Data binding between the data island and the data-bound controls keeps the two synchronized. You can also add validation code to the data that is independent of the controls. For more information, see Binding Data to Controls in Office Solutions.

Host controls are extended versions of native objects in the Excel and Word object models. Unlike the native objects, host controls can be bound directly to managed data objects. For more information, see Host Items and Host Controls Overview and Windows Forms Controls on Office Documents Overview.

To access cached data in a document, you can use the ServerDocument class. This class is part of the Visual Studio Tools for Office runtime, and it can be used on a server without running Excel or Word. When the user opens the document after you modify the cached data, any controls that are bound to the data are automatically synchronized to the changes, and the user is presented with the updated data. For more information, see Accessing Data in Documents on the Server.

Excel and Word are not needed to write to the data on the server, only to view it on the client. Excel and Word do not even need to be installed on the server. This provides improved scalability and the ability to perform fast batch processing of documents that contain data islands.

Storing data in the data island enables offline scenarios. When a user first opens a document or requests the document from the server, the data island is filled with the most recent data. The data island is cached in the document and is then available offline. The user (and your code) can manipulate the data, even though no live connection is available. When the user reconnects, the changes to the data can be propagated back to a server data source.

Custom XML parts were introduced in the 2007 Microsoft Office system as a way to store arbitrary pieces of XML in a document. Although custom XML parts are useful in many of the same scenarios as the data cache, there are some differences between the data island and custom XML parts. For more information about custom XML parts, see Custom XML Parts Overview.

The following table lists some of the differences and similarities.

Data cache

Custom XML parts

Which Office applications can use these?

Document-level customizations for the following applications:

  • Excel

  • Word

Document-level and application-level solutions for the following applications:

  • Excel

  • PowerPoint

  • Word

What types of data can you store?

Any public object in your customization assembly that meets certain requirements. For more information, see Caching Data.

Any XML data.

Can you access the data without starting Microsoft Office applications?

Yes, by using the ServerDocument class provided by the Visual Studio Tools for Office runtime.

Yes, by using classes in the System.IO.Packaging namespace, or by using the Open XML Format SDK.

Show:
© 2014 Microsoft