Re: Returning complex (ObjectResult<T>) data types

769 views
Skip to first unread message

Govert van Drimmelen

unread,
May 23, 2013, 6:00:55 PM5/23/13
to Excel-DNA
Hi Nicholas,

You'll have to convert your ObjectResult into a 2D object[,] array of
primitive types (strings, doubles etc.)
Best might be to build a List<object[]> with each basic data item
converted to an object[] array first:

I think you can enumerate through the ObjectResult using

List<object[]> resultList = new List<object[]>();
foreach (zzzz_Result item in result)
{
// Here you need some code to convert zzzz_Result to an
object[]
object[] itemData = object[5];
itemData[0] = item.Name;
itemData[1] = item.Value;
/// etc
resultList.Add(itemData);
}

object[,] result = new object[resultList.Count, 5];
// now fill in result from resultList.....

Finally, change the return type of your function to object[,] and be
sure to enter it an an array function in Excel (Ctrl+Shift+Enter).

Each step is a bit tricky....

Regards,
Govert

* * * * * * * * * * * * * * * * * * * * * * * * * * * *

Ensure that the Excel-DNA project continues by
making your donation - http://excel-dna.net/support/

* * * * * * * * * * * * * * * * * * * * * * * * * * * *



On May 23, 3:32 pm, nicholasjdaw...@gmail.com wrote:
> I'm a bit of a novice in the C# world, and would like to return results
> from the MS Entity Framework:
>
> For example:
>
> public object[] MyFunc ()
> {
>             Entities e = new Entities();
>             ObjectResult<zzzz_Result> result = e.GetData(a,b,c,d);
>
> return ???;
>
> }
>
> Has anyone had to cast the ObjectResult to an Object in order to return it
> to Excel?
> Do I use the ToArray() method?
>
> Sorry, I'm a bit lost on how to return the data. Any hints apprecitated
Reply all
Reply to author
Forward
0 new messages