What reference do I need to use Microsoft.Office.Interop.Excel in .NET?

user850010 picture user850010 · May 7, 2012 · Viewed 227.7k times · Source

I am interested in using C# to manipulate/Automate Excel files.

After browsing the web I have found VSTO but it seems you can not use that in Visual Studio Express Edition so I can not use that.

Just few minutes ago I noticed a question in this site that used this namespace in its code:

Microsoft.Office.Interop.Excel

So I am wondering if all I need to use that is add necessary reference and if so which reference to add?

UPDATE

I installed "Primary Interop Assemblies" as the accepted answer suggested but for some reason they are still missing in the Add Reference dialog under ".NET" but they are present in GAC.

So I just added the reference using "Browse" and located Microsoft.Office.Interop.Excel.dll in GAC folder.

But looking for similar questions on this site regarding adding reference from GAC it seems this is not recommended.

Answer

moribvndvs picture moribvndvs · May 7, 2012

Update (thanks user2347528)

These assemblies are available as NuGet packages, which is much easier than my original answer.

You can install by either right clicking on References in your project and selecting Manage NuGet packages... and searching for one of the packages listed below, or install using the Package Manager Console:

PM> Install-Package Microsoft.Office.Interop.Excel

These are available as "Primary Interop Assemblies", which can be installed with Office, or downloaded and installed separately. How to: Install Office Primary Interop Assemblies.

Once those are installed, you can reference them in your project in the Add Reference dialog, under .NET. If you do not see those Microsoft.Office.Interop assemblies listed, then they have not been installed yet. Install them from your setup, or download and install them separately (see my link above for the downloads).