Introduction to C# and Excel Integration


This is the introductory chapter in a set of four chapters on Excel programming with C#. We give a global overview of the Excel Object Model and how to access its objects using C#. We also discuss a number of concepts that will help our understanding of the material in later chapters. We also give an overview of the different kinds of Excel add-ins that can be created using languages such as C#, VB.NET and VBA. In later chapters we discuss Automation and COM (Component Object Model) add-ins in more detail. We also discuss the Datasim Excel Visualisation Package that we created in order to display information in Excel.


In this section we discuss the object model in Excel. We can view the Excel application as a hierarchy of objects and these can be programmatically accessed in languages such as C#, VBA, VB.NET, unmanaged C++ and C++/CLI. A simplified version of the Excel object hierarchy is shown in Figure 20.1. In general, an object at a given level contains zero or more objects one level below it. For example, Excel application contains several workbooks and a workbook contains several worksheets. Other objects not shown in Figure 20.1 are:

  • A table in a worksheet.
  • A ListBox control on a UserForm.
  • A chart series on a chart.
  • A data point on a chart.

Figure 20.1 Excel Object Model (simplified)

Our interest lies in accessing the object model from C#. Most of the documentation ...

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.