I\'m creating a plugin for excel, i would like to know how is it possible to create new rows to display a list or array
I created a sample function :
[Exce
Considering you're returning an array, you can span the results across columns by entering the formula in array mode.
Select the cells horizontally, type in the formula, and press CTRL
+SHIFT
+ENTER
.
For example, selecting A1:C1
and typing =StringSplit("a b c")
as an array formula, will display the three elements of the array in the three cells selected.
You need to know upfront how many elements will be returned and select the correct number of cells appropriately.
If you don't know how many elements will be returned, then you might want to look at Resizing Excel UDF result arrays, but it's a hack and should be avoided if possible.
Here is an example implementation of a helper macro that will resize your result array to the right size.
If you wanted to return rows and columns, you just need to return an object[,]
[ExcelFunction(Description = "Returns 2x2 matrix")]
public static object GetValues()
{
return new object[,]
{
{1, 2},
{3, 4},
};
}
Everything else stays the same. You should return the number of elements that correspond to the number of cells selected by the user, unless you go with **resizing result arrays as per above.