Summary: Learn how to use the Microsoft Office Excel 2007 object library to programmatically create a table that contains a calculated column.
Here is a summary of the Steps obtained from Microsoft's MSDN:
-
Creating a Windows Console Application project in Visual Studio 2005.
-
Adding a reference to the Excel 12.0 Object Library to the project. This marks the project as making use of the Excel 12.0 Object Library.
-
Importing the Microsoft.Office.Interop.Excel namespace. This allows the code to use the classes and types exposed as part of theMicrosoft.Office.Interop.Excel namespace without having to specify the fully qualified namespace path.
-
Creating a data insertion helper method. This method makes it easier to insert data for the table into the worksheet.
-
Declaring helper variables to hold references to the Excel objects used in the calculated column creation code.
-
Creating an instance of the Excel ApplicationClass object. This is the top-most class in the Excel object model hierarchy and is the starting point for working with the other classes in the object model.
-
Creating a workbook and adding a worksheet to it. The code shows how to create a workbook with a single worksheet in it.
-
Inserting table data into the worksheet. The sample code shows how to call the data insertion helper method to add the data for the table to the worksheet.
-
Implementing the table and calculated column creation code. The sample code adds a table to the worksheet. It illustrates how to use theWorksheet.ListObjects.Add method to add a table to the worksheet and how to add a formula to a cell, causing the formula to be automatically extended to the other rows in the column.
-
Saving the workbook, exiting Excel, and releasing the references to its COM objects so that Excel can unload from memory.
Obtained from: http://msdn.microsoft.com/en-us/library/bb491102.aspx