Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.E

来源:互联网 发布:程序员笔记本推荐 知乎 编辑:程序博客网 时间:2024/05/22 11:50

      前段时间做了个将Txt中数据导出到Excel中的C#小应用程序,一直都运行很好的。今天突然有同事安装时,报如下错:

************** Exception Text **************
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: 不支持此接口 (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at TxtToExcelDemo.ExcelOperate.ExcelFileOperate.CreateExcelFile()
   at TxtToExcelDemo.MainForm.btnLoadOut_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

       经过排查,终于找到问题所在,原来是他的office安装不正确,重新安装office后,就可以解决问题了

 

原创粉丝点击