从C#调用XLL文件中的函数 [英] Calling function in XLL file from C#

查看:296
本文介绍了从C#调用XLL文件中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有功能的xll文件,我想从C#调用该功能. 这个xll文件用在excel中.任何人都知道怎么做吗?.我试着刷新xll文件,但我没有得到值.如果我像开始->程序-> excel这样打开excel, 在excel中,如果我直接给出该函数,我将获得正确的值.如果我在c#中自动执行excel,并从Microsoft.Office.Interop.Excel中打开excel,并应用了该函数,则会出错

I have a xll file which have a function and I want to call that function from C#. This xll file is used in excel.any body have idea how to do that?.I tried refrencing the xll file but I am not getting the value.If I open excel like start-->programms-->excel and in excel if i directly give the function I am getting right value.Same thing If i automate excel in c# and opened excel from Microsoft.Office.Interop.Excel and applied the function I am getting error

推荐答案

您可以使用一些工具:

XLL Plus
XLL主机

在MSDN

The question has also been asked on MSDN Use XLL from C#, this is the answer:

如果它是一个COM项目,则可以通过添加引用"窗口中的"COM"选项卡添加它.

If it is a COM project, you can add it via the COM tab in the Add reference window.

如果需要从dll创建.NET程序集,则可以尝试使用类型库导入工具围绕dll创建包装器:

If you need to create a .NET assembly from the dll, you can try to use Type Library Import tool to create a wrapper around the dll:

tlbimp.exe xll.dll /out:xllnet.dll

如果对象不支持COM,而仅支持本机调用,则需要使用DllImport属性平台调用这些方法.有关更多信息,请参见Platform Invoke教程.

If the object does not support COM, but only native calls, you will need to platform invoke the methods using the DllImport attribute. See the Platform Invoke tutorial for more information.


我给出了所有3条建议,但没有任何运气.鉴于XLL工具的作者 Excel-DNA 建议使用我怀疑在Winform/中使用XLL的工具WPF/控制台或Web应用程序并非易事: https://stackoverflow.com/a/2865023/495455


I gave all 3 suggestions a go but didn't have any luck. Given the author of the XLL tool Excel-DNA recommends using a tool I suspect consuming a XLL in a Winform/WPF/Console or Web app is not trivial: https://stackoverflow.com/a/2865023/495455

这篇关于从C#调用XLL文件中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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