问题描述
未处理System.InvalidCastExceptionHResult=-2147467262Message=无法将类型为“Microsoft.Office.Interop.Excel.ApplicationClass”的COM对象强制转换为接口类型“Microsoft.Office.Interop.Excel._Application”。此操作失败的原因是对IID为“{000208D5-0000-0000-C000-000000000046}”的接口的COM组件调用QueryInterface因以下错误而失败:加载类型库/DLL时出错。(异常来自HRESULT:0x80029C4A(TYPE_E_CANTLOADLIBRARY))。Source=mscorlibStackTrace:在System.StubHelpers.StubHelpers.GetCOMIPFromRCW(ObjectobjSrc,IntPtrpCPCMD,IntPtr&ppTarget,Boolean&pfNeedsRelease)在Microsoft.Office.Interop.Excel.ApplicationClass.set_Visible(BooleanRHS)在CreateExcelWorksheet.Main()位置c:UsersEVANDocumentsMicrosoftPressshishiCreateExcelWorksheetCreateExcelWorksheetProgram.cs:行号16在System.AppDomain._nExecuteAssembly(RuntimeAssemblyassembly,String[]args)在System.AppDomain.ExecuteAssembly(StringassemblyFile,EvidenceassemblySecurity,String[]args)在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在System.Threading.ThreadHelper.ThreadStart_Context(Objectstate)在System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate,BooleanpreserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate,BooleanpreserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate)在System.Threading.ThreadHelper.ThreadStart()InnerException:
解决方案
解决方案二:
你可以安装下VSTO试试或者https://www.microsoft.com/zh-CN/download/details.aspx?id=48217