Compartir a través de


Microsoft Excel Technology Sample

This sample demonstrates using Microsoft Excel, the spreadsheet component of Microsoft Office, from a managed application. The programmatic functionality of Microsoft Excel is exposed through .NET Programmability Support. Excel is used as a COM server in this sample to illustrate the possibilities for interaction between managed code and the Microsoft Office System.

NoteNote

This sample requires Microsoft Office 2003 with .NET Programmability Support and Microsoft Office Primary Interop Assemblies.

For information about using the samples, see the following topics:

To install .NET Programmability Support

  1. Open the Control Panel and select Add or Remove Programs.

  2. Select Microsoft Office 2003 or Microsoft Excel 2003, and click Change. In the dialog, ensure the Add or Remove Features option button is selected, and click Next.

  3. Select the Choose Advanced Customization of Applications checkbox, and then click Next.

  4. Expand the node for Excel and click the downward-facing arrow adjacent to .NET Programmability Support. Select Run from My Computer.

  5. Click Update.

To install the Microsoft Office Primary Interop Assemblies

A PIA contains type definitions for a native COM object. Once installed, specifying a type library when building an interop application is unnecessary.

To build the sample using the Command Prompt

  1. Open a Command Prompt window and navigate to one of the language-specific subdirectories under the Excel directory.

  2. Enter the following command, using the correct solution file for your programming language.

    msbuild AutoExcelVB.sln

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to one of the language-specific subdirectories under the Excel directory.

  2. Double-click the icon for AutoExcelCP.sln, AutoExcelCS.sln or AutoExcelVB.sln, depending on your choice of programming language, to open the file in Visual Studio.

  3. In the Build menu, choose Build Solution.

The sample will be built in the default \bin or \bin\Debug directory.

To run the sample

  1. In the Command Prompt window, navigate to the directory that contains the new executable file.

  2. Type AutoExcel.exe at the command line.

  3. When you have finished, switch to the Command Prompt window and press Enter to close Excel and exit the application.

NoteNote

This sample builds a console application. You must launch it using the command prompt in order to view its output. At the end of execution the sample leaves the Excel window open to show the results.

Requirements

Microsoft Office 2003

Primary Interop Assemblies for Microsoft Office

.NET Framework Version: 2.0, 1.1, 1.0

Remarks

Review comments in the source code for more information about Microsoft Office interoperability.

See Also

Reference

Array
COMException
InvokeMember
Math
Missing
System.Reflection
System.Runtime.InteropServices

Other Resources

Design Considerations for Interoperation
Interoperating with Unmanaged Code
Managed and Unmanaged Events
Marshaling Data with COM Interop