Office Automation Sample
This sample demonstrates automation of Microsoft Agent, Microsoft Word, and Microsoft Excel. When referencing the various COM Office assemblies, Visual Studio automatically creates COM runtime callable wrappers (RCW) so you can program against them from within the .NET Framework.
To get samples and instructions for installing them
Do one or more of the following:
On the Help menu, click Samples.
The Readme displays information about samples.
Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.
Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.
For more information, see Visual Studio Samples.
Security Note: |
---|
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties. |
To run this sample
- Press F5.
Requirements
If you want to hear Merlin speak, you may need to install the speech recognition pack, which is included with Microsoft Office XP but not installed by default. For instructions on how to do this, see: Install speech recognition (https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/input\_speech\_install.mspx).
Demonstrates
Three TabPage controls are added to a TabControl to demonstrate three programming tasks:
Microsoft Agent The Office Agent library makes the Merlin character appear and perform. Before the Merlin character can appear, an instance of the AgentObjects.Controller object must be created. From this object, an IAgentCtlCharacter object is accessed that represents Merlin. The IAgentCtlCharacter implements a Play method that is used to control the various animations. For more on Microsoft Agent, see the articles and SDK documentation at https://msdn.microsoft.com.
Microsoft Word A simple text file is displayed in a RichTextBox control. An instance of Word is started and the Word application is used to check the spelling of the text in the RichTextBox control.
Microsoft Excel Create and fill a DataSet from an XML document and then use the DataBind method to bind it to a DataGrid. Then export the contents of the DataSet to an Excel spreadsheet and run an Excel function that calculates the average of the values in a column.
See Also
Tasks
How to: Install Office Primary Interop Assemblies
How to: Target Office Applications Through Primary Interop Assemblies