Excel DNA check for object?

Mar 3, 2015 at 6:59 PM
Edited Mar 3, 2015 at 7:01 PM
Greetings!
I have found the following code here:
<DnaLibrary Language="CS">
<![CDATA[
    using ExcelDna.Integration;
    using System.Collections.Generic;
    public class MyFunctions
    {
    [ExcelFunction(Description="Joins cell values", Category="PPCTemplate")]
    public static object RangeJoin2(object[,] cells)
    {
    List<string> list = new List<string>();
    foreach (object o in cells)
    list.Add(o.ToString());
    return string.Join(" ", list.ToArray());    
    }

}
    ]]>
    </DnaLibrary>
However, if there's a blank cell between the data it concatenates it as ExcelDna.Integration.ExcelEmpty. I have tried the following, but, without luck,
if ( ____is ExcelEmpty)
        {
            return "";
        }
Where ___ has been: cells, object, object o, list
I just want the function to concatatenate if there's data, if not, skip it and continue with the next cell and so on.

The VBA function that I want to replace is working as I need, but, I can't find a way to do it in C language:
Function ConcatMe2(Rng As Range) As String
Dim vArr As Variant
Dim v As Variant
vArr = Rng

   ConcatMe2 = vbNullString

   For Each v In vArr
      ConcatMe2 = ConcatMe2 & " " & v
   Next v

End Function
Coordinator
Mar 3, 2015 at 7:40 PM
I think you're close.

What about:

foreach (object o in cells) 
{ 
    if ( !(o is ExcelEmpty) )
        list.Add(o.ToString());
}


Marked as answer by Sgdva on 3/3/2015 at 2:45 PM
Mar 3, 2015 at 9:46 PM
Edited Mar 3, 2015 at 9:46 PM
Great! is working now! Thanks a lot!