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" } };
}
}
}