No way to import Namespace for Microsoft.Office.Interop.Excel - c#

Since 3 days I've been trying every link I find on the issue, but always get the "CS0234: The type or namespace name 'Office' does not exist in the namespace 'Microsoft'" error. I need to convert Excel to PDF in c#.
This is my set-up:
Windows Server 2012 R2
Office Professional Plus 2010 (in Spanish! That should not be a
problem though?!)
Microsoft Office 2010 Primary Interop Assemblies
Microsoft Visual Studio Express 2015 for Web
I won't see Microsoft.Office.Interop.Excel among the Assemblies under .NET; trying to find a way, I added the "Microsoft Excel 14.0 Object Library" to my project which made the "Microsoft.Office.Interop.Excel" reference at least appear in the list. But that dll points to C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll and seems to be useless as the error remains. I reinstalled everything several times and updated VS Express for Web from 2013 to 2015.
I read somewhere (Can I still use Microsoft.Office.Interop assemblies with office 2013?) that PIAs are considered a historical artifact and that one can do without. That was only more confusing and didn't help.

Related

Visual Studio 2017 C# project with Microsoft.Office.Interop.Word 2016/365 coded and 2010 production

I'm coding one of my first projects in Visual Studio 2017 using the Microsoft Office Interop Tools to basically open some Word files, extract some content and export it to an XML file.
I know that on the target machine Office should be installed and actually on that PC a 2010 installation is licensed, while on my PC I have a 365 suite.
The first build was working only on my PC, with missing references errors to the interop library on the production PC, so I've downloaded the Microsoft Office 2010: Primary Interop Assemblies Redistributable
https://www.microsoft.com/en-us/download/details.aspx?id=3508 to include as a reference in my project, replacing the 2016 one.
First difficulty was: Once installed I cannot find the files on my drive, nor a reference inside visual studio, nor in the documentation. Is there any info about where to pick the dll?
So I unzipped from the cab the WORDPIA.DLL on an handy directory and referenced it in my project.
While is it working locally, it isn't yet on the production PC.
I'm sure I'm missing a lot of points on this topic, VS & C# are not my territory, but I need some tips to finish the project.
Go back to the original project (or reference the version of the PIAs installed on your machine). The redistributable is intended for installing to an Office 2010 machine where the PIAs were not installed. It's not meant to be used in the manner you envision.
Now click each "interop" reference entry and look at the Properties window. There should be a setting for "Embed Interop Types". Set that to True. This should make the project version-independent as it will contain the PIA information your project uses.
Note that "embed interop types" was introduced with .NET Framework 4.0 and is not available for earlier versions of the Framework. If an earlier version is a requirement, then you have to use late-binding or develop your project using Office 2010.

Excel Addin For Excel 2010 & Excel 2013 in Visual Studio

I have a Excel addin written in VBA which iterates through used range of a sheet and manipulates cell values. Its a simple addin but now user requirements have changed and I want to develop it in C# in Visual studio. For this purpose i was looking into VSTO but as far as i can understand in visual studio you can develop addin for a single version of excel. I have to give support for excel 2010 and excel 2013. What should I do to overcome this issue. which visual studio version i should use?
Any version of Visual Studio from 2010 to the present should be able to create VSTO Add-ins for Excel 2010. From VS 2012 onwards, also for Office 2013. Which set of templates you see in the later versions depends on 1) the version of Office installed and 2) the version of the .NET Framework selected when creating the project (4.0 for 2010; 4.5 for later). More information can be found on this page: https://blogs.msdn.microsoft.com/vsto/2013/03/06/office-developer-tools-for-visual-studio-2012-now-available-with-office-2013-and-net-framework-4-5-support/
Note that you should have only one version of Office installed in the development environment.
If possible, you should develop the Add-in for Excel 2010. An Add-in developed for an older version will run for a newer version, without you needing to do anything in addition - assuming Microsoft hasn't made changes to the parts of the object model you use which will "break" it. Since Microsoft pays special attention to backwards compatibility, this is usually not a problem, but thorough testing is important. It is not necessary to re-build or otherwise change the installation for installing to a newer version of Office.
One important reason to develop against the older version is that forwards compatibility is not supported. In other words, if you should use something in the newer version that's not present in the older one, that code will fail.
Also, the VSTO functionality will automatically "re-map" references made to an older set of PIAs to the newer ones for a newer version of Office. The reverse is not the case.
If for some reason it's not possible to program using the older version, as long as you have the .NET Framework 4.0 (or later) you can use the "Embed Interop types" property of a Reference to embed the PIA information in your project, so that it travels with your solution instead of referencing the PIAs installed in the GAC and makes them version independent. This is fine, in theory, but requires very thorough and careful testing since - besides the forwards compatibility problem - the actual information embedded does not always behave correctly.
you need to install visual studio 2013 for VSTO version 13 that support Excel 2013, but you can support excel 2010 by creating the installer file from the application. and there is no other way to support two different version from the code base at the same time
Thanks

Can I build a project referencing Office 2013 COM components without installing Office 2013?

We have a small project that references Microsoft.Office.Interop.Word 8.6.0.0. The reference was added via the COM tab in the Add References window, so the underlying .csproj reference is a COMReference.
I'm trying to set up a build server at the moment, and according to the answer to this question, it's no longer possible to work directly with Office 2013 PIAs.
This is incredibly frustrating as I don't want to have to deploy an instance of Office to my build server. Is there any way to achieve what I'm trying to do without installing Office?

Microsoft.Office.Interop error even after installing PIAs

We have a large project which builds fine on several machines. I am in the process of installing a development system on a new machine and have a problem building because the Microsoft.Office.Interop namespace is missing.
I have Office 2010 installed and have installed the PIAs. I have removed/re-added the Office references in the project - they still seem to have the yellow triangle.
Still no luck.
Could there be anything I haven't tried yet?
Sounds like you're doing something wrong while adding the reference. You could see to these similar threads if they are of help:
https://stackoverflow.com/a/16054365/1493524
PIA's Installed but still receiving interop error
Adding Office 2010 Interop (PIA) in Visual Studio 2012

Microsoft.Office.Interop.Outlook 2010 Reference in VS 2012 Using .Net 2.0

I was tying to add a Reference to Microsoft.Office.Interop.Outlook Namespace in to my web project i'm using .Net 2.0 And visual studio 2012
Question
Which one of the following is the one i should choose to work with Outlook 2010
I tried to google this and i couldn't find any thing
Or here is GAC path
C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll
you can browse manually to folder
C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\14.0.0.0__71e9bce111e9429c\
and consequently choose Microsoft.Office.Interop.Outlook.dll
You've chosen wrong tab in Reference Manager. Choose this tab:
Then find Microsoft.Office.Interop.Outlook library. If you have multiple choice, then look at File Version info - there's a version of Office you can work with: 12.* - 2007, 14.* - 2010, 15.* - 2012.
The best choice is 14.* but the others will mostly work too.
I also need to worry you that Microsoft suggests not to use interop on server side (link)

Categories

Resources