C# and Excel Integration COM Add-ins


In this chapter we give an introduction to COM add-ins, what they are, how to create them and how to call them from Excel. A COM add-in is a COM component that implements a special interface called IDTExtensibility2 that is responsible for connecting to and disconnecting from Excel. The Excel client can call the add-in to compute some quantity or to transfer data between Excel and other applications, for example. It is important to note that both input to and output from the add-in are realised by Excel cells and ranges which we can access from C#.

We discuss the following topics in this chapter:

  • The IDTExtensibility2 interface and its methods OnConnection() and OnDisconnection().
  • Which code we need to write when creating a COM add-in.
  • Creating a COM add-in and using the Shared add-in wizard.
  • Using COM add-ins with Excel.
  • Initial examples.
  • An introduction to Excel-DNA.

When describing the actual steps to create a COM add-in we avoid describing which dialog boxes, check boxes and buttons to use because these tend to change between versions of Visual Studio. Instead, we describe the high-level what and how steps that show how to create add-ins. The most up-to-date Microsoft documentation should be consulted. The authors have also created some visual demos on www.datasimfinancial.com.

We assume that the reader is familiar with the most important principles underlying COM. For a clear overview of this subject, ...

Get C# for Financial Markets now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.