使用功能区设计器在vb.net中实现Excel自动化 [英] Excel automation in vb.net by using ribbon designer
问题描述
目前,我正在VB.Net中从事Excel自动化.我有一个新的addIn项目,并向其添加了功能区设计器.当我编写以下代码时:
Hi,
Currently I am working on Excel automation in VB.Net. I have a new addIn project and have added ribbon designer to it. When I am writing the following code :
Dim curBook As Excel.Workbook
curBook = New Excel.Workbook
所以基本上就像是,我被困在程序的第一步.它是一个基本的自动化程序,我将使用合并和着色来格式化工作表.
我还需要将对象实例添加到活动工作表,以便可以访问所有
公式.
我遇到的异常是:
So basically its like, I am stuck at the first step of my program. Its a basic automation program and I will format sheet with merging and colouring.
I also need to get an object instance to the active sheet so that I can access all the
formulae.
The exception that I encountered is like :
Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154.
at MT_try1.Ribbon1..ctor() in C:\Documents and Settings\Ankit Sharma\My Documents\Visual Studio 2008\Projects\Excel Projects\MT_try1\MT_try1\Ribbon1.vb:line 7
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at Microsoft.Office.Tools.AddIn.CreateRibbonObjects()
at Microsoft.Office.Tools.AddIn.GetRibbonObjects()
at Microsoft.Office.Tools.AddIn.CreateRibbonExtensibilityObject()
at Microsoft.Office.Tools.AddIn.get_RibbonExtensibility()
at Microsoft.Office.Tools.AddIn.Initialize()
at MT_try1.ThisAddIn.Initialize() in C:\Documents and Settings\Ankit Sharma\My Documents\Visual Studio 2008\Projects\Excel Projects\MT_try1\MT_try1\ThisAddIn.Designer.vb:line 40
at Microsoft.VisualStudio.Tools.Office.EntryPointComponentBase.Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.Initialize(IServiceProvider hostContext)
at Microsoft.VisualStudio.Tools.Applications.AddInAdapter.ExecutePhase(ExecutionPhases executionPhases)
at Microsoft.VisualStudio.Tools.Office.Internal.OfficeAddInAdapterBase.InitializeEntryPointsHelper()
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3634 (GDR.050727-3600)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Runtime.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Runtime.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Runtime.v10.0.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3634 (GDR.050727-3600)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.1 built by: SP
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Hosting.v10.0.dll
----------------------------------------
System.AddIn
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.3676 built by: GDR
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.AddIn/3.5.0.0__b77a5c561934e089/System.AddIn.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.v10.0.dll
----------------------------------------
System.Deployment
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Deployment/2.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
----------------------------------------
System.Security
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3613 (GDR.050727-3600)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Security/2.0.0.0__b03f5f7f11d50a3a/System.Security.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3637 (GDR.050727-3600)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3639 (GDR.050727-3600)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Xml.Linq
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.1 built by: SP
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml.Linq/3.5.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
MT_try1
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Ankit%20Sharma/My%20Documents/Visual%20Studio%202008/Projects/Excel%20Projects/MT_try1/MT_try1/bin/Debug/MT_try1.DLL
----------------------------------------
Microsoft.Office.Tools.Common.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Tools.Common.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Common.v9.0.dll
----------------------------------------
Microsoft.Office.Tools.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Tools.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Excel.AddInAdapter.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Excel.AddInAdapter.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Excel.AddInAdapter.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.AddInAdapter.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.AddInAdapter.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.AddInAdapter.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.AddInAdapter.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.AddInAdapter.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.AddInAdapter.v9.0.dll
----------------------------------------
System.AddIn.Contract
Assembly Version: 2.0.0.0
Win32 Version: 3.5.30729.1 built by: SP
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.AddIn.Contract/2.0.0.0__b03f5f7f11d50a3a/System.AddIn.Contract.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Contract.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Contract.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Contract.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Contract.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Contract.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Contract.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Adapter.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Adapter.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Adapter.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Excel.HostAdapter.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Excel.HostAdapter.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Excel.HostAdapter.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.HostAdapter.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.HostAdapter.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.HostAdapter.v10.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Excel.AddInProxy.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Excel.AddInProxy.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Excel.AddInProxy.v9.0.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Office.Contract.v10.0
Assembly Version: 10.0.0.0
Win32 Version: 10.0.31119.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Office.Contract.v10.0/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Office.Contract.v10.0.dll
----------------------------------------
Microsoft.Office.Interop.Excel
Assembly Version: 12.0.0.0
Win32 Version: 12.0.6600.1000
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Excel/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0
Assembly Version: 9.0.0.0
Win32 Version: 9.0.30729.4130
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0/9.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll
----------------------------------------
office
Assembly Version: 12.0.0.0
Win32 Version: 12.0.6425.1000
CodeBase: file:///C:/WINDOWS/assembly/GAC/office/12.0.0.0__71e9bce111e9429c/office.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
请帮帮我!!!!
在此先感谢
Please help me!!!!
thanks in advance
推荐答案
你能告诉我为什么你没写这个吗:
Could you tell me why you didnt write this:
Dim curBook as New Excel.Workbook
而且错误似乎缺少dll:
http://social.msdn.microsoft.com /forums/en-US/vbgeneral/thread/88a6ea68-f476-4231-822f-27fabe59f458/ [
And the error seems to be missing dlls:
http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/88a6ea68-f476-4231-822f-27fabe59f458/[^]
这篇关于使用功能区设计器在vb.net中实现Excel自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!