Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Office (Excel) COM interop on Mac OSX using .NET Core?

I work for a team that currently specializes in creating windows desktop applications in C#/.NET that interwork with local user instances of Microsoft Excel via Office COM Interop. I am currently charged with specifying a new product but I’ve been told that the project will not go ahead unless the app can run on Mac as well as Windows – that is, we have to be able to produce a Mac version of the app that can install natively on OSX and interact with the object model of a user’s instance of Microsoft Excel for Mac.

Running the app with Parallels, Mono or Wine (see COM Interop Through Wine in OSX, which was never answered) is not a solution because the spec for the app requires that the user machine is not modified in any way. We just have to assume the user has a licenced local copy of Excel running, and work with that… which is what we have always done on Windows, where it works great.

I think .NET Core is the answer but I can’t find anywhere where it says definitely that we can (or will be able to) access the Excel Object Library from C# when running .NET Core on Mac OSX with a local copy of Excel for Mac installed. Can anybody point me please to where this has been discussed already; but if not, then tell me how I can go about finding out from Microsoft if this is in their roadmap for .NET Core?

like image 503
Geoffff Avatar asked Dec 15 '16 20:12

Geoffff


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

Where is Microsoft Office Interop Excel?

Go to the Project \Add Refference click on the "Browse" tab, locate the Microsoft. Office. Interop. Excel.

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

Yes, you are right. You need Excel to be installed to use the Excel Manipulation feature with Microsoft. Office. Interop.


1 Answers

I have received some helpful feedback from a similarly worded question on MSDN. I have also posted an issue on the .NET Core Github, but I think it is already clear what the answer is to this, which is as follows:

  • The .NET Core team may perhaps be persuadable to add access to the Office.Interop.Excel namespace in the .NET Core Class library, but only for Windows
  • This cannot be done for .NET Core on OSX because the environment is not suitable for interchanging COM objects.
  • This leaves only two options for manipulating objects in Excel for Mac, both of which already exist: Embedded VBA or Javascript (Office Add-ins).
  • Office Addins is a great new solution for web-driven data-oriented objects in Excel - and its multiplatform nature is awesome - so is enjoying the main focus of development from Microsoft. However it is not intended to be any match for the performance of COM for managing complex spreadsheets, since that's not its focus.
  • Which means there is no solution for managing objects within Excel for Mac using C#, in the way that there is on Windows, and there doesn't appear to be any prospect of one.

The bottom line: The very welcome .NET Core initiative looked like it was a fix, but sadly isn't, because of architecture limitations on OSX.

I have submitted this as an answer because I think I've come to the end of the line of enquiry on it, but if anyone thinks any of the above is incorrect, please shout!

Thanks.

like image 58
Geoffff Avatar answered Nov 04 '22 12:11

Geoffff