如何使用VSTO 2005 SE使用C#Excel加载项创建Excel 2003 UDF [英] How to create Excel 2003 UDF with a C# Excel add-in using VSTO 2005 SE

查看:204
本文介绍了如何使用VSTO 2005 SE使用C#Excel加载项创建Excel 2003 UDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了一篇有关使用VBA在VSTO托管代码中创建Excel UDF的文章: http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx

I saw an article on creating Excel UDFs in VSTO managed code, using VBA: http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx.

但是我想使用VSTO 2005 SE在C#Excel加载项中使用它,有谁能帮忙?

However I want to get this working in a C# Excel add-in using VSTO 2005 SE, can any one help?

我尝试了Romain指出的技术,但是在尝试加载Excel时出现以下异常:

I tried the technique Romain pointed out but when trying to load Excel I get the following exception:


自定义程序集无法
被发现或无法加载。您
仍然可以编辑和保存
文档.....

The customization assembly could not be found or could not be loaded. You can still edit and save the document.....

详细信息:

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))


************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
at Microsoft.Office.Interop.Excel._Application.Run(Object Macro, Object Arg1, Object Arg2, Object Arg3, Object Arg4, Object Arg5, Object Arg6, Object Arg7, Object Arg8, Object Arg9, Object Arg10, Object Arg11, Object Arg12, Object Arg13, Object Arg14, Object Arg15, Object Arg16, Object Arg17, Object Arg18, Object Arg19, Object Arg20, Object Arg21, Object Arg22, Object Arg23, Object Arg24, Object Arg25, Object Arg26, Object Arg27, Object Arg28, Object Arg29, Object Arg30)
at ExcelWorkbook4.ThisWorkbook.ThisWorkbook_Startup(Object sender, EventArgs e) in C:\projects\ExcelWorkbook4\ExcelWorkbook4\ThisWorkbook.cs:line 42
at Microsoft.Office.Tools.Excel.Workbook.OnStartup()
at ExcelWorkbook4.ThisWorkbook.FinishInitialization() in C:\projects\ExcelWorkbook4\ExcelWorkbook4\ThisWorkbook.Designer.cs:line 66
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode()
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomization(IHostServiceProvider serviceProvider)


************** Loaded Assemblies **************


推荐答案

您还应该看看ExcelDna- http://www.codeplex.com/exceldna 。 ExcelDna允许托管程序集通过本机.xll接口向Excel公开用户定义的函数(UDF)和宏。该项目是开源的,可以免费商业使用。

You should also have a look at ExcelDna - http://www.codeplex.com/exceldna. ExcelDna allows managed assemblies to expose user-defined functions (UDFs) and macros to Excel through the native .xll interface. The project is open-source and freely allows commercial use.

您可以用C#,Visual Basic,F#,Java(使用IKVM.NET)编写用户定义的函数。 ,并且可以编译为.dll或通过基于文本的脚本文件公开。支持从Excel 97到Excel 2007的Excel版本。

Your user-defined functions can be written in C#, Visual Basic, F#, Java (using IKVM.NET), and can be compiled to a .dll or exposed through a text-based script file. Excel versions from Excel 97 to Excel 2007 are supported.

使用.xll界面而不是制作自动化加载项的一些优点包括:

Some advantages of using the .xll interface rather than making automation add-ins include:


  • Excel的较早版本受支持,

  • 部署更容易,因为不需要COM注册并且无需引用用户定义的函数工作表中的公式不会绑定到外接程序的位置,并且

  • 通过ExcelDna公开的UDF函数的性能非常好。

这篇关于如何使用VSTO 2005 SE使用C#Excel加载项创建Excel 2003 UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆