简体   繁体   English

如何在不安装Excel的情况下修复InteropServices.COMException?

[英]How can I fix InteropServices.COMException without installing Excel?

I have a C# console application that creates Excel spreadsheets. 我有一个创建Excel电子表格的C#控制台应用程序。 I added Interop.Excel NuGet package to the application. 我向应用程序添加了Interop.Excel NuGet包。 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... 由于以下错误,检索具有CLSID {00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80040154未注册类...

I tried to make the platform to be x64 or x86 rather than Any CPU, but it did not help. 我试图将平台设置为x64或x86,而不是Any CPU,但这并没有帮助。 Installing Excel on the VM is not acceptable. 在VM上安装Excel是不可接受的。 Is there any way to solve without installation? 没有安装有什么办法解决吗?

Thanks. 谢谢。

Sorry, a COM interop package does not include the application itself, only CLR callable functions that ease interop with the application. 抱歉,COM互操作包不包括应用程序本身,仅包括可简化与应用程序互操作的CLR可调用函数。 Since Microsoft Excel is a licensed product, you have to purchase/install it separately. 由于Microsoft Excel是许可产品,因此您必须单独购买/安装。

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. 没有免费的午餐,但是您可能可以使用COM远程处理通过interop软件包从VM调用在主机上运行的Excel副本。 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. 出于相当明显的安全原因,默认情况下不会启用此功能,但是如果您将此用于自动测试,则可能会解决这种使用问题。

If you need to interact only with XLS X files, you may try third-party libraries that do not depend on Excel. 如果仅需要与XLS X文件进行交互,则可以尝试不依赖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. XLSX是一种基于XML的开放格式 (它是一堆XML的zip文件),现在已有10多年的历史了。 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. 我强烈建议使用EPPlus( GitHubNuGetSO ),它比使用互操作性非常稳定,功能丰富且幅度更快。

If you need to interact with legacy XLS files, then you're out of luck. 如果您需要与旧版XLS文件进行交互,那么您就不走运了。 It's an old proprietary format that MS kept very close to their heart. 这是一种旧的专有格式,MS始终贴近他们的内心。 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). 有第三方库可以对其进行操作,但是没有一个好的库是免费的(无论如何,几年前还是免费的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InteropServices.COMException - InteropServices.COMException com 异常 excel InteropServices.COMException - c# - com exception excel InteropServices.COMException - c# 为什么使用此代码会得到“ InteropServices.COMException / ForwardCallToInvokeMember”? - Why would I get, “InteropServices.COMException / ForwardCallToInvokeMember” with this code? C# AutoIt InteropServices.COMException 错误 - C# AutoIt InteropServices.COMException error 将项目添加到 ObservableCollection 时出现 InteropServices.COMException - InteropServices.COMException when adding item to ObservableCollection 为什么我在尝试从 C# 启动 QTP 时收到 InteropServices.COMException? - Why do I get an InteropServices.COMException when attempting to launch QTP from C#? 间歇性的“ InteropServices.COMException / ForwardCallToInvokeMember”在范围单元格上访问Value2 - Intermittent “InteropServices.COMException / ForwardCallToInvokeMember” accessing Value2 on Range cell Excel中interopServices C#的COMException - COMException with interopServices C# in Excel 如何使用SpeechRecognizer UWP解决System.Runtime.InteropServices.COMException? - How can I solve System.Runtime.InteropServices.COMException using SpeechRecognizer UWP? InteropServices.COMException(0x800A1066):在Teamcity下命令失败 - InteropServices.COMException (0x800A1066): Command failed under Teamcity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM