How to reference Microsoft.Office.Interop.Excel dll?

C#ExcelReferenceVisual Studio-2012Vsto

C# Problem Overview


I had developed a system that deals with excel sheets in 2006 using MS VS 2005. Now, I can not use the same reference with MS VS 2012.

var app = new Microsoft.Office.Interop.Excel.Application();
Workbooks wbs = app.Workbooks;

C# Solutions


Solution 1 - C#

Use NuGet (VS 2013+):

The easiest way in any recent version of Visual Studio is to just use the NuGet package manager. (Even VS2013, with the NuGet Package Manager for Visual Studio 2013 extension.)

Right-click on "References" and choose "Manage NuGet Packages...", then just search for Excel.

enter image description here


VS 2012:

Older versions of VS didn't have access to NuGet.

  • Right-click on "References" and select "Add Reference".
  • Select "Extensions" on the left.
  • Look for Microsoft.Office.Interop.Excel.
    (Note that you can just type "excel" into the search box in the upper-right corner.)

![VS2012/2013 References](http://i.stack.imgur.com/J9l9j.png "VS 2012 / 2013")


VS 2008 / 2010:

  • Right-click on "References" and select "Add Reference".
  • Select the ".NET" tab.
  • Look for Microsoft.Office.Interop.Excel.

![VS 2010 References](http://i.stack.imgur.com/L1FKU.png "VS 2008 / 2010")

Solution 2 - C#

You can also try installing it in Visual Studio via Package Manager.

Run Install-Package Microsoft.Office.Interop.Excel in the Package Console. This will automatically add it as a project reference.

Use is like this:

Using Excel=Microsoft.Office.Interop.Excel;

Solution 3 - C#

If you have VS 2013 Express and you cant find Microsoft.Office namespace, try this ('Microsoft Excel 12.0 Object Library' if you want to use Office 2007)

enter image description here

Solution 4 - C#

Building off of Mulfix's answer, if you have Visual Studio Community 2015, try Add Reference... -> COM -> Type Libraries -> 'Microsoft Excel 15.0 Object Library'.

Solution 5 - C#

Instead of early binding the reference, there's an open source project called NetOffice that abstracts this from your project, making life much easier. That way you don't have to rely on your users having a specific version of Office installed.

NetOffice Codeplex site.

Solution 6 - C#

You have to check which version of Excel you are targeting?

If you are targeting Excel 2010 use version 14 (as per Grant's screenshot answer), Excel 2007 use version 12 . You can not support Excel 2003 using vS2012 as they do not have the correct Interop dll installed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMoe_AlView Question on Stackoverflow
Solution 1 - C#Grant WinneyView Answer on Stackoverflow
Solution 2 - C#CYCLONEView Answer on Stackoverflow
Solution 3 - C#MuflixView Answer on Stackoverflow
Solution 4 - C#Daniel.VenezianoView Answer on Stackoverflow
Solution 5 - C#LawManView Answer on Stackoverflow
Solution 6 - C#mas_oz2k1View Answer on Stackoverflow