简体   繁体   English

无法将“System._ComObject”类型的 COM object 转换为“microsoft.Office.Interop.Excel.Application””

[英]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:如果这不是与代码相关的错误,请从注册表中删除以下给定键:

  1. Run the windows registry editor - Start-->Run --> regedit.exe运行windows注册表编辑器--开始-->运行-->regedit.exe
  2. Try to remove extra keys from the 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.这里也有一些类似的线程你可以参考。

暂无
暂无

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

相关问题 C# outlook: Unable to cast COM object of type 'System._ComObject' to Interface type 'Microsoft.Office.Interop.Outlook.MailItem.' - C# outlook : Unable to cast COM object of type 'System._ComObject' to Interface type 'Microsoft.Office.Interop.Outlook.MailItem.' 无法将“microsoft.Office.Interop.Excel.ApplicationClass”类型的 COM 对象转换为“microsoft.Office.Interop.Excel.Application”” - unable to cast COM object of type 'microsoft.Office.Interop.Excel.ApplicationClass' to 'microsoft.Office.Interop.Excel.Application'" 无法将类型为“System.__ComObject”的 COM 对象转换为接口类型“Interop.PeachwServer.Application” - Sage SDK 2018 CreateCustomerDemo c# - Unable to cast COM object of type 'System.__ComObject' to interface type 'Interop.PeachwServer.Application' - Sage SDK 2018 CreateCustomerDemo c# 无法转换“Microsoft.Office.Interop.Excel.WorksheetClass”类型的COM对象 - Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.WorksheetClass' Microsoft.Office.Interop.Excel.Application - 调用不同版本的 Excel - Microsoft.Office.Interop.Excel.Application - Invokeing Different Versions of Excel 将Microsoft.Office.Interop.Excel.Application转换为byte [] - Convert Microsoft.Office.Interop.Excel.Application to byte[] 如何在asp.net输出流上编写Microsoft.Office.Interop.Excel.Application对象 - How to write Microsoft.Office.Interop.Excel.Application object on asp.net output stream 错误:在为 Microsoft.Office.Interop.Excel.Application 实例化 object 时出现 800700c1 - Error : 800700c1 in instantiating an object for Microsoft.Office.Interop.Excel.Application :'无法将类型为'System .__ ComObject'的COM对象转换为接口类型 - : 'Unable to cast COM object of type 'System.__ComObject' to interface type C#: some of machines are throwing following error: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - C#: some of machines are throwing following error: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM