简体   繁体   中英

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. Any help is appreciated.

This problem is mostly caused by incorrect COM Interop settings/keys in the Windows registry. This can be caused by installing a newer version of Microsoft Office, and then removing it and installing an older version instead. 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
  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. Then, try again. If the problem still exists, you can completely uninstall, reboot, and then reinstall Office.

Here are also some similar threads you can refer to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM