开发者

Calling function in XLL file from C#

I have a xll开发者_C百科 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


You probably won't be able to invoke the function directly because an XLL will expect the Excel interfaces to be driving. You'd have to do some serious faking.

Automating it through Excel will work though.


An xll is just a dll. If you know the signature of the function you want to call, you can call it just like any other function. If you don't know the signature but can load the add-in in Excel, there is a way to get Excel to tell you the signature.

Automation only works if you are running Excel. There is no need for that once you know the signature.


There is a few tools you can use:

XLL Plus
XLL Host


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

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

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

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜