Calling excel UDF from .net?

2019-08-17 11:53发布

I am trying to call UDF in excel from C#?When I open the excel from start-->pro the UDF function works.but when I try to apply the formula from C# automation I am getting Name?# any help below is the code itried

Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application(); oXL.Visible = true; Microsoft.Office.Interop.Excel._Workbook oWB; Microsoft.Office.Interop.Excel._Worksheet oSheet;

        oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));

        oXL.AddIns.Add("ciqfunctions.udf", false)

        Microsoft.Office.Interop.Excel.AddIn adc = oXL.AddIns.Item["Capital IQ Worksheet Functions"];
        adc.Installed = true;
        oXL.AddIns.Add("ciqfunctions.udf", false).Installed = true;

        all below register xlls returns false.any idea

        bool clloaded = oXL.RegisterXLL(@"C:\Program Files\Capital IQ\Office Plug-in\ciqfunctions.xll");

        bool clloaded1 = oXL.RegisterXLL("ciqfunctions.xll");

        bool clloaded2 = oXL.RegisterXLL("ciqfunctions.udf");

        bool clloaded3 = oXL.RegisterXLL(oXL.DefaultFilePath + "\\CIQAddinLib.dll"); 


        I am applying formula by creating range

and range.formula="=some udf formula" but it puts Name#? any idea

标签: c# .net c++ excel
1条回答
你好瞎i
2楼-- · 2019-08-17 12:41

I think this line is ok and should work, almost:

oXL.AddIns.Add("ciqfunctions.udf", false).Installed = true;

at least according to my readings. Try it with the full path of the file which in your case is this one:

@"C:\Program Files\Capital IQ\Office Plug-in\ciqfunctions.xll"

everything else seems to be ok, steps are also shown here:

Loading an Excel Add-in

查看更多
登录 后发表回答