Reputation: 5375
I have a C# console application that creates Excel spreadsheets. I added Interop.Excel NuGet package to the application. When I am trying to run it on a virtual machine, I am getting an exception:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered...
I tried to make the platform to be x64 or x86 rather than Any CPU, but it did not help. Installing Excel on the VM is not acceptable. Is there any way to solve without installation?
Thanks.
Upvotes: 0
Views: 132
Reputation: 4105
If you need to interact only with XLSX files, you may try third-party libraries that do not depend on Excel. XLSX is an open, XML-based format (it's a zip file of a bunch of XMLs) and is now more than 10 years old. There are many good quality, open source libraries that you can use to process them.
I would highly recommend EPPlus (GitHub, NuGet, SO) which has been very stable, feature-rich, and magnitudes faster than using interops.
If you need to interact with legacy XLS files, then you're out of luck. It's an old proprietary format that MS kept very close to their heart. There are third-party libraries that can operate on them, but none of the good ones are free (as at a few years ago anyway).
Upvotes: 1
Reputation: 6864
Sorry, a COM interop package does not include the application itself, only CLR callable functions that ease interop with the application. Since Microsoft Excel is a licensed product, you have to purchase/install it separately.
No free lunch, but it might be possible for you to use COM remoting to invoke a copy of Excel running on your host machine from the VM through the interop package. For fairly obvious security reasons, this isn't going to be enabled by default, but if you are using this for automated test purposes, it might address that sort of use.
Upvotes: 3