This documentation is archived and is not being maintained.

XML Merge Sample

Visual Studio 2005

Download sample

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

    -or-

    Visual Studio 2005 Professional Edition

  • VSTO 2005 SE installed in the development environment

  • 2007 Microsoft Office system

This sample demonstrates how to merge data from an XML data source into a Microsoft Office Word 2007 document or a Microsoft Office Excel 2007 workbook by using an application-level add-in. The sample uses new features in the 2007 Microsoft Office system to provide more options for designing a user interface (UI) for a custom Office solution. These options include custom task panes and a custom Ribbon group.

The sample solution includes three projects:

  • XMLMergeWordAddIn is an add-in project for Word.

  • XMLMergeExcelAddIn is an add-in project for Excel.

  • XMLMergeControls is a class library that includes components shared by both of the add-in projects. For more information, see Components of the XMLMergeControls Project.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

For information about how to install the sample project on your computer, see How to: Download Sample Files in Help Topics.

To run this sample

  1. Open the XMLMerge solution.

  2. In Solution Explorer, right-click the add-in project that you want to run and then click Set As Startup Project.

    If you want to run the Word add-in, set XMLMergeWordAddIn as the startup project. If you want to run the Excel add-in, set XMLMergeExcelAddIn as the startup project.

    NoteNote

    The add-in projects demonstrate the same features.

  3. Press F5.

    Word or Excel starts and loads the add-in.

  4. Click the customized tab on the Ribbon for the application you are using:

    • On the Word Ribbon, click the Mailings tab.

    • On the Excel Ribbon, click the Data tab.

  5. Locate the custom group labeled XML Merge on the tab.

  6. In the XML Merge group, click XML Merge Help.

    The XML Merge Add-in for Excel or XML Merge Add-in for Word task pane appears. This is a custom task pane that includes instructions for using the add-in.

  7. Follow the instructions in the task pane to merge XML data into the document or workbook.

    NoteNote

    As you follow the steps, the instructions in the task pane will be replaced by a view of a data source XML schema. You can switch between the instructions and the view of the schema by clicking Help or Show Fields at the bottom of the task pane.

Requirements

This sample requires the following applications:

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

    -or-

    Visual Studio 2005 Professional Edition

  • VSTO 2005 SE installed in the development environment.

  • 2007 Microsoft Office system.

For more information, see Features Available by Product Combination.

Demonstrates

Ribbon Extensibility

This sample demonstrates the following Ribbon concepts:

  • How to extend a built-in tab on the Ribbon by adding a new group that contains a dynamic menu, a toggle button, and buttons.

  • How to use callback methods to set button and menu images, to set the enabled state for the controls, and to fill the content of a dynamic menu.

  • How to extend the Microsoft Office Button menu by adding a custom option to the Print menu.

Custom Task Panes

This sample demonstrates the following custom task pane concepts:

  • How to create a custom task pane that alternates between displaying instructions for the sample and displaying XML elements that users can add to the document or workbook.

Document Context

This sample demonstrates the following concepts related to document context:

  • How to synchronize the Ribbon and custom task pane to match the state of the document:

    • The Display Pane, Remove Data Source, and Perform Merge buttons in the Ribbon are enabled only after the user has chosen an XML data source for the active document.

    • The custom task pane is visible or hidden depending on the state of the Display Pane button on the Ribbon.

  • How to store data in the document or workbook as a custom XML part.

Components of the XMLMergeControls Project

The following table describes the components in the XMLMergeControls project.

Component Description

XMLMergeRibbon.cs

XMLMergeRibbon.xml

A code file and an XML file that defines a custom Ribbon UI.

XMLMerge.cs

A UserControl that provides the UI for the custom task pane.

DocManager.cs

Document management classes that coordinate state between the custom Ribbon UI, the custom task pane, and the active document or workbook.

customers.xml

customers.xsd

products.xml

products.xsd

XML and XML schema (.xsd) files that serve as data sources for customer and product information.

XMLMergeResources.resx

Resources shared by both add-ins.

XmlMergeHelp.htm

Sample instructions that are displayed in the custom task pane.

See Also

Show: