[英]unable to cast COM object of type 'System._ComObject' to 'microsoft.Office.Interop.Excel.Application'"
I am working with a WinForm project, in the project, there's a function that takes a datatable to export to excel file, it works fine on my working pc running Visual Studio 2022 and pre-installed Office 365, but when I run the program on another PC that's running Office 2007, it reports this exception, I have already tried removing registery(the machine having this issue had 1.0 and 1.6, I removed 1.0 to match my own PC) and uninstalling Office 2007 and install 2016 instead, nothing worked for me, I am pretty sure this is not a code related issue.我正在使用一个 WinForm 项目,在项目中,有一个 function 需要一个数据表来导出到 excel 文件,它在我运行 Visual Studio 2022 并预装 Office 365 的工作电脑上运行良好,但是当我在另一台运行 Office 2007 的 PC,它报告此异常,我已经尝试删除 registery(有此问题的机器有 1.0 和 1.6,我删除了 1.0 以匹配我自己的 PC)并卸载 Office 2007 并安装 2016,没有任何效果我,我很确定这不是与代码相关的问题。 Any help is appreciated.
任何帮助表示赞赏。
This problem is mostly caused by incorrect COM Interop settings/keys in the Windows registry.此问题主要是由 Windows 注册表中不正确的 COM 互操作设置/键引起的。 This can be caused by installing a newer version of Microsoft Office, and then removing it and installing an older version instead.
这可能是由于安装了较新版本的 Microsoft Office,然后将其删除并安装了较旧版本。 There are other ways this could happen.
还有其他可能发生这种情况的方式。
If this is not a code related error than please remove below given key from registry:如果这不是与代码相关的错误,请从注册表中删除以下给定键:
HKEY_CLASSES_ROOT-->TypeLib-->{00020813-0000-0000-C000-000000000046} --> 1.8/1.7
If not successful, you can try to repair your Office 365 in the control panel.如果不成功,您可以尝试在控制面板中修复您的 Office 365。 Then, try again.
然后,再试一次。 If the problem still exists, you can completely uninstall, reboot, and then reinstall Office.
如果问题仍然存在,您可以完全卸载、重新启动,然后重新安装 Office。
Here are also some similar threads you can refer to.这里也有一些类似的线程你可以参考。
unable to cast COM object of type 'microsoft.Office.Interop.Excel.ApplicationClass' to 'microsoft.Office.Interop.Excel.Application'" unable to cast COM object of type 'microsoft.Office.Interop.Excel.ApplicationClass' to 'microsoft.Office.Interop.Excel.Application'"
How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'” How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'”
How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'” How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.