Distribution of an application that requires Microsoft.Office.Interop.Excel - c#

I have a c# (VS 2015) application that references Microsoft.Office.Interop.Excel
My code includes oXL = new Microsoft.Office.Interop.Excel.Application(); as well as the above reference.
If I compile and install that application on a machine that already has both Office 2013 and .Net 4.0 but when I search that computer I cannot find Microsoft.Office.Interop.Excel.dll on it anywhere which, I assume, is what I need.
I saw here:
By default, PIA’s are embedded in your solution when you build it so you don’t have to distribute PIAs to users as a prerequisite to using your VSTO Add-in or customization.
When I build my application I don't get Microsoft.Office.Interop.Excel.dll included in my Release folder (like I do with other referenced .dlls).
Do I need to add that manually or is the only way to get this installed to also install the Office Primary Interop Assemblies Redistributable from Microsoft?

Go to the properties of the reference and set copylocal to true.
Interop libs have them set to false by default.
This will copy the DLL, when you build the project.
The Copy Local property (corresponding to CopyLocal) determines
whether a reference is copied to the local bin path.
At run time, a
reference must be located in either the Global Assembly Cache (GAC) or
the output path of the project. If this property is set to true, the
reference is copied to the output path of the project at run time.
For a more in depth look into copy local see msdn

Jason, as far I know, you can select the version and Office package required to install your application.
If you are using Visual Studio, you can go to Settings (of your application) and insert the dependecies.
Check those links:
Deployment and Dependencies
How to: Create and Remove Project Dependencies

Jason, you have also to REFERENCE the MICROSOFT OFFICE XX.X OBJECT LIBRARY.
The XX.X is the release you have there.
When your project runs at client, VS will seach in GAC_MSIL to see if he/she has Office there.
Do not try to add EXCEL libraries because it won´t function. Your user must have Office to your code run.

The .NET application will look for the dll in the global assemblies and bind to whatever appropriate dll there is dynamically.
DLL = dynamically linked library
There are different dlls for dofferent versions of office and on different platforms (32 bit versus 64 bit).
In short, do NOT include the dll in your package.
Catch exceptions in case office is not installed.

Related

Open a project referencing "MS-Office Object Library" on multiple development machines

I'm using two computers, one has Office 2010 installed and the other has Office 2016. The first one is my main PC.
Let's say I started a project on the main PC. If I add a reference to any of the following:
Microsoft.Office.Interop.Word (Microsoft Word 14.0 Object Library).
Microsoft.Office.Interop.Excel (Microsoft Excel 14.0 Object Library).
Microsoft.Office.Interop.PowerPoint (Microsoft PowerPoint 14.0 Object Library).
..and then open the project on the second PC, Visual Studio will automatically select the applicable version for all of them (i.e., "Microsoft XXXX 16.0 Object Library") since "Embed Interop Type" property is set to true.
So far so good, but when I add a reference to Microsoft.Office.Core (Microsoft Office 14.0 Object Library), I can't get the same behavior, that is, when I open the project on the second PC, I find the reference with the same version (14.0) flagged with an icon indicating that the reference is missing along with warnings telling me the same thing (the reference cannot be found).
Obviously, if I remove the reference and replace it with the newer version (16.0), everything works fine except -of course- that I won't be able to open the solution on the main PC anymore.
So, my questions are:
Why doesn't it select the appropriate version for Microsoft.Office.Core like what happens with Interop.Excel, Interop.Word, etc?
Is there a solution for this so I can open the project seamlessly between the two computers?
Please note:
The main focus is not about running the application by the end user with different versions of Office (this have been asked and answered many times before). I'm more concerned about opening the solution/project on a secondary development machine with a different version of Office installed.
In case that's relevant, this is a WinForms application.
Update:
I tried copying the MSO.DLL file to a local 'lib' folder but whenever I add it as a reference, it shows "C:\Windows\assembly\GAC_MSIL\Office\14.0.0.0__71e9bce111e9429c\Office.dll" as the path of the reference. Then, no matter whether I disable/enable the Embed Interop Types property, it still doesn't compile on the secondary development machine.
Although I'm not quite sure I fully get Eugene's answer, it helped by giving me the idea of adding the PIA references in the Assemblies tab, not the COM tab and still have the Embed Interop Type property set to true. That actually seems to work but I'm not sure if not using the COM references might have any downsides. Does it?
You need to copy interop assemblies (Microsoft Word/Excel/PowerPoint/Core 14.0 Object Libraries) to a local folder in the solution. And then you can add them as references, so they will be accessible on both machines and you will be able to open the project seamlessly between the two computers.

Cannot add Excel to Project as a COM object

I am needing to create an Excel spreadsheet from a c# project, but I cannot add the reference to the Excel COM object.
I am using Visual Studio 2010 and office 2013. I've clicked on the References folder and selected Add Reference, and then navigated to the COM tab, setting them in alphabetical order. I looked through, but there was no reference to Microsoft.Office.Interop.Excel.
Trying to resolve the issue, I downloaded and installed the PIAs for Office 2010, but references still were not added. I'm not sure where these files would be located on the hard-drive, so I cannot just browse to them (or copy one to the project Resource folder and reference it there).
Does anyone have an idea as to why I cannot see the references?
Additional Information
I managed to get the Microsoft.Office.Interop.dll file from a coworker for Office 2013, but I was not able to reference it from my project since I am working in .NET 3.5. My manager does not want me to update the project to .NET 4.0, so it looks like I will need to use the Office 2010 PIAs I installed. Unfortunately, installing them did not add them to the list, and I haven't been able to find the dll's to add them by browsing to them.
I doubt that it will make a difference, but my dev system is Windows 8.

Visual Studio Referencing

I am using C# Winforms and when I add a reference to the project for Microsoft.Interop.Office.Excel v12.0.0.0, it automatically adds a COM reference to C:\Program Files\Microsoft Office\Office14\EXCEL.exe.
This .exe isn't found on any other machines, and as such, it won't work on other devices. Is there a way to import that file, or make it not reference to that file?
Any microsoft office tools like Microsoft.Office.Interof.Excel are part of Microsoft Primary Interop Assemblies called PIA, which can be downloaded separately and installed on production machine.
All version of PIAs can be downloaded from msdn. e.g. Office PIA
Msdn Pia link
Or you can copy them to Library Folder in your solution and reference these assembly from Library folder local to your solution.

Can't locate Microsoft.Office.Interop.Word in Reference List

I was given this solution to a problem I had, since I didn't know how to integrate MS Word with C#: http://www.dotnetperls.com/word
I looked into this solution, and I can't locate Microsoft.Office.Interop.Word in the reference list. I can't find it under COM Objects either. What am I missing? I am using Visual Studio Express 2012.
EDIT:
The answer to this question is that you HAVE to install MS Office on your computer.
You need Microsoft Word xx Object Library.
You can download the Primary Interop Assemblies from here.
http://www.microsoft.com/en-us/download/details.aspx?id=3508
You may also use NuGet Package Manager in order to install the reference.
Go to Project -> Manage NuGet Packages...
Search for "Interop.Word" and install that package.
Good thing about it is that you don't need to think about where the dll is located. When another person will check out the solution, NuGet will get all needed packages onto their machine.
you might need to install the assemblies separately,if you did not choose to install them during your office installation.
MSDN:
You must install the Microsoft Office primary interop assemblies
(PIAs) in the global assembly cache of your development computer
before you can perform certain development tasks. Typically, the PIAs
are installed automatically when you install Office on the
development computer. However, in some cases you might need to install
the PIAs separately.
More here
Check if the library (Microsoft.Office.Interop.word) is present in the assembly folder of windows (C:\Windows\assembly) else you can install it from http://www.microsoft.com/en-us/download/details.aspx?id=3508
Now you just need locate it in your visual studio.
Right click on the consoleApplication(or name of you application) in SolutionExplorer window and
Go to Add -> References-> Browse and find C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.word or similar directory.
press ok and your can now use the library in your application.

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.
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).
Just had this problem myself and accepted answer didn't help me but I solved it with:
Add reference > Browse > C: > Windows > assembly > GAC > Microsoft.Office.Interop.Excel > 12.0.0.0_etc > Microsoft.Office.Interop.Excel.dll
Answers didn't help me to solve my problem, I couldn't find (and browse) the assemblies although I installed them using Microsoft's msi installer. For me, the excel assembly is located under C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll
Just add reference of Microsoft.Office.Interop.Excel.
It includes MicroSoft Excel related classes, no need to add more references.
I guess what you are trying to do is add Microsoft.Office.Interop.Excel with using statement with out adding its reference in your application, in that case it wont be found. Before calling it with using statement you need to add a reference to ur application. Right click on References and add the Excel Interop reference.
Add reference > Browse > C: > Windows > assembly > GAC > Microsoft.Office.Interop.Excel > 12.0.0.0_wasd.. > Microsoft.Office.Interop.Excel.dll
I found it located under Assemblies->Extensions in VS2013.
If you have Microsoft Office installed, then you should be able to add a reference to Interop.Excel.
For example, the PC I'm typing this on has MSVS 2010 C# Express and Office 2010. I can add a reference to Microsoft.Office.Interop.Excel 11.0.0.0.
'Hope that helps
its in the com component, named:
"Microsoft Office 14 Object Library"
I just had the same problem, but none of these answers helped me. I did find the dll on my pc in the location Mostey noted: (C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll), but this is not the one that was referenced in the project I was trying to get building.
The reference in our project in Visual Studio 2012 was pointing to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\. This location was empty for me, but it worked fine for everyone else. It took a number of tries, but I finally tracked down a working installer. I hope this saves others the same hassle!
--> Office Tools Bundle installer for VS2012 <--
This was located on the Office Documentation and Download page. Scroll down to Tools Downloads. There's also currently one for VS2013.
The best option since office 2007 is using Open XML SDK for it.
We used Word.Interop but it halt sometimes, and it is not recommend for Microsoft, to use it as a server side document formatting, so Open XML SDK lets you creates word documents on DOCX and Open XML formats very easily.
It lets you going well with scability, confidence ( the files, if it is corrupted can be rebuild ), and another very fine characteristics.
Here is super solid solution, you just need have excell.dll in your Debug/Release folder
Mine is 77,824 bytes, I downloaded it as a file, this also explain why some people have Debug compiled but Release not or vice versa.
Trento
1.Download and install: Microsoft Office Developer Tools
2.Add references from:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office15
I had the same issue and the Microsoft.Office.Interop was not appearing in "Add Reference" option once I upgraded VS2012 to VS2015. I basically repaired the installation (Control Panel > Programs & Features > VS 2012 > Right click Change > Repair) and added the Microsoft Office component. After that the same solution started working.
Make sure your project is 32 bit.
I had this problem, as soon as I ticked "Prefer 32 bit and rebuilt" all the Office Interop assemblies where available in Reference->Assemblies->Search "Office".

Categories