Why the second Excel function is not recognized

Mar 31, 2014 at 6:57 PM
Hi,

I'm pretty new to Excel-DNA and am now trying to build a simple Excel-Function follow the instruction.
I've successfully implement the SayHello example based on the instruction. But then when I add another ExcelFunction, it can not be recognized by Excel (see my code below):

public class MyFuctions
{
    [ExcelFunction(Name = "SayHello", Description = "My first .NET function")]
    public static string SayHello(string name)
    {
        return "Hello " + name;
    }

    [ExcelFunction(Name = "arcMapSQLOR", Description = "Join a list of values using an OR operation")]
    public static string arcMapSQLOR(string[] array, string fieldName, string fieldDelimiter)
    {
        //Check the type of the input array
        if (array.Count() == 0)
        {
            return "";
        }
        else
        {
            Type arrType = array[0].GetType();
            string fieldwithDel = fieldDelimiter.Trim() + fieldName.Trim() + fieldDelimiter.Trim();
            IList<string> strList = new List<string>();
            if (arrType.Name == "String")
            {
                foreach (string item in array)
                {
                    strList.Add(fieldwithDel + " = " + string.Format("'{0}'", item.ToString()));
                }
            }
            string[] strArray = strList.ToArray();
            return strArrayConcatenate(strArray, " OR ");
        }
    }


    public static string strArrayConcatenate(string[] array, string concatenateStr)
    {
        StringBuilder sBuilder = new StringBuilder();
        for (int i = 0; i < array.Count() - 1; i++)
        {
            sBuilder.Append(array[i] + concatenateStr);
        }
        sBuilder.Append(array[array.Count() - 1]);
        return sBuilder.ToString();
    }
}
Is that because there are something wrong with my code or there should only be one ExcelFunction in one class?
Please let me know if you have any clues on this.
Thank you so much!

Zhenyu
Coordinator
Mar 31, 2014 at 7:03 PM
Hi Zhenyu,

String arrays are not supported as parameters at the moment.
You can see a details of the supported types here: https://exceldna.codeplex.com/wikipage?title=Reference&referringTitle=Documentation

You should change them to object[], and then deal with the different data types you might get, or just call .ToString() to turn into a string.

Regards,
Govert
Mar 31, 2014 at 7:06 PM
Hi Govert,

Thank you so much for getting back to me so fast.
I'll try to use object[] then.
Thanks again!

Zhenyu