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
3 Answers
There is a few tools you can use:
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

- 1
- 1

- 61,933
- 36
- 195
- 321
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.

- 601,492
- 42
- 1,072
- 1,490
-
David thanks for the info.IF i automate through excel using excel interop and applying the formula in xll like oRng.Formula="=getnumber('abcd','IQ_COMPANY_ID')"; I am getting com exception error.Have any idea how to open an excel with the xll enabled. – user933316 Sep 13 '11 at 19:09
-
I've no idea. I don't know anything about the XLL or how you are driving it. – David Heffernan Sep 13 '11 at 19:10
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.

- 761
- 4
- 7