Dynamic array related weird issue

34 views
Skip to first unread message

Kedar Kulkarni

unread,
May 18, 2022, 6:03:33 PM5/18/22
to Excel-DNA
I am currently trying to port our large addin to office 365 to return dynamic array where I am trying to return object[,] array from my method and it only shows object[0,0] value in excel and not dynamic array. I am on office 365 and DA is supported for sure. 

The code is similar to the below. The functions are registered dynamically. I can't share the exact code. The below code works, but similar code does not with our larger addin. Not sure if this is helpful but I don't have a way to reproduce this issue and I continue to investigate.

*** About the example below.
I created a function with function registration writetest2 below - it is the only code inside invoke(). It just shows "one" in the cell where the function is entered and I am expecting it to return 2x2 array. In below case WriteTest and WriteTest2 both give same return value but not in my larger addin.

I just want to know if there is a known scenario where we just get single result even though the method returns object[,] array. I tried to enter the formula as a CSE array formula but all cells show the first value only. Its kind of weird as I can see an array is returned but then I am unsure where the other values vanish.. 

thanks in advance. 



using ExcelDna.Integration;
using ExcelDna.Registration;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace DCTools
{
    public class AsyncTestAddIn : IExcelAddIn
    {
        public void AutoOpen()
        {
            var methodInfo = typeof(ExcelFunctionDynamic).GetMethod(nameof(ExcelFunctionDynamic.Invoke));

            var excelFunctionDynamic = new ExcelFunctionDynamic();

            var registrations = new List<ExcelFunctionRegistration>();

            var reg = new ExcelFunctionRegistration(
                Expression.Lambda(Expression.Call(
                    Expression.Constant(excelFunctionDynamic),
                    methodInfo)), new ExcelFunctionAttribute() {Name = "WriteTest2" });


            registrations.Add(reg);

            registrations.RegisterFunctions();
        }

        public void AutoClose()
        {
        }

        public class ExcelFunctionDynamic
        {
            public object Invoke() => new object[2, 2] { { "one", "two" }, { "three", "four" } };
        }


        public static class ExcelFunctions
        {
            [ExcelFunction(Name = "WriteTest")]
            public static object WriteTest() => new object[2, 2] { { "one", "two" }, { "three", "four" } };
        }
    }
}

Kedar Kulkarni

unread,
May 19, 2022, 9:08:09 AM5/19/22
to Excel-DNA
I could recreate the issue - it was caused by @ in the cell formula that was in the test file I was using.. If =@WriteTest2() should reproduce the issue. 

Govert van Drimmelen

unread,
May 20, 2022, 3:22:17 AM5/20/22
to exce...@googlegroups.com

OK great – I’m glad you figured it out.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/d0840f76-c425-4035-a21f-21c987a30036n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages