To use the objects of a program that supports automation (a server), you have to reference the program's type library. A program's type library (also called its object library) is a file containing a description of the program's object model. After you've referenced the type library of an automation server (also called a component), you can access the objects of the server as though they were internal Visual C# objects. You create the reference to Excel's automation library much like you created a reference to the System.Data namespace in Hour 21, "Working with a Database." To create a reference to the Excel library, follow these steps:
By the Way If you don't see Microsoft Excel 11.0 Object Library in your list of available COM references, you probably don't have Excel 2003 installed, and this example will not work. By the Way Visual C# doesn't work directly with COM components (as did previous versions of Visual C#). Instead, it interacts through a wrapper, a set of code and objects that works as an intermediary between Visual C# and a COM component. When you add the reference to a COM component, .NET automatically creates this wrapper for you. |