Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 623
user850010 Avatar asked May 07 '12 07:05

user850010


People also ask

How do I use Microsoft Office Interop Excel in .NET core?

First, Remove 'Microsoft. Office. Interop. Excel' nuget package, and then add reference to 'Microsoft Excel 16.0 Object Library' (right click the project -> 'Add' -> 'Reference' -> search and add 'Microsoft Excel 16.0 Object Library' ).


1 Answers

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 
  • Microsoft.Office.Interop.Excel
  • Microsoft.Office.Interop.Word
  • Microsoft.Office.Interop.Outlook
  • Microsoft.Office.Interop.PowerPoint
  • Microsoft.Office.Interop.Graph

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).

like image 120
moribvndvs Avatar answered Oct 02 '22 20:10

moribvndvs