Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get Microsoft.Office.Interop reference to work

I have a C# winforms app and I am simply trying to open an Excel sheet. When I try to add a reference to Microsoft.Office.Interop, the "Office" part is red and says "Can't resolve symbol 'Office'".

When I attempt to build, the error is:

The type or namespace name 'Office' does not exist in the namespace 'Microsoft'      (are you missing an assembly reference?) 

I have Office 2012 installed, and I think I have the Primary Interop Assemblies installed... but I'm not positive.

I know that this should be so easy, but I've been looking around for an answer to this for almost an hour and just can't figure it out. Thanks in advance!

like image 934
Ben Strombeck Avatar asked Jul 23 '13 22:07

Ben Strombeck


People also ask

Do I need to have Office installed to use Microsoft Office Interop Excel DLL?

Question TLDR: Yes. You need to have Excel installed or an exception will be thrown.


1 Answers

Use NuGet Package Manager in VS2015

  • Right click references in your visual studio project
  • Select Manage NuGet Packages
  • Type microsoft.office in the search box
  • Select Microsoft.Office.Interop.Excel
  • Click Install
  • Rebuild your solution
like image 180
Simon Hutchison Avatar answered Sep 22 '22 19:09

Simon Hutchison