How to return an array from an XLL function

I'm new to writing XLL, Does anyone know how to return a 6x1 array in Excel?

Below is my function (some codes came from another message):

__declspec(dllexport) LPXLOPER12 WINAPI GetArr(char* arg1, char* arg2) { vector<double> arr = functionReturnVector; XLOPER12 list; list.xltype = xltypeMulti | xlbitDLLFree; list.val.array.lparray = new XLOPER12[6]; list.val.array.rows = 6; list.val.array.columns = 1; for(int i = 0; i < 6; ++i) { list.val.array.lparray[i] = arr[i]; // error: IntelliSense: no operator "=" matches these operands } return &list; } 

[2013-02-23] I am currently reading codes from XLL RETURN ARRAY and reviewing my code, it can compile, but returns 0 ...

 __declspec(dllexport) LPXLOPER12 WINAPI GetArr(void) { XLOPER xlArray, xlValues[2]; xlValues[0].xltype = xltypeNum; xlValues[1].xltype = xltypeNum; xlValues[0].val.num = 11; xlValues[1].val.num = 17; xlArray.xltype = xltypeMulti|xlbitDLLFree; xlArray.val.array.rows = 1; xlArray.val.array.columns = 2; xlArray.val.array.lparray = &xlValues; return &xlArray; } 
+4
source share
2 answers

Now I can print the 1X2 array in an Excel worksheet, below is my code.

** use Func U signature type

1. Select one row and two columns

2.Type command = GetArray () in the first cell

3.Ctrl + shift + enter

  __declspec(dllexport) LPXLOPER12 WINAPI GetArray(void) { static XLOPER12 xlArray; XLOPER12 xlValues[2]; xlValues[0].xltype = xltypeNum; xlValues[1].xltype = xltypeNum; xlValues[0].val.num = 123; xlValues[1].val.num = 456; xlArray.xltype = xltypeMulti|xlbitDLLFree; xlArray.val.array.rows = 1; xlArray.val.array.columns = 2; xlArray.val.array.lparray = &xlValues; return (LPXLOPER12)&xlArray; } 
+3
source

Maybe http://xll.codplex.com can help you solve your problem, but like other people trying to help you, your code seems pretty far off shore.

At a time when you don’t understand whether you agree to agree with him, and to continue to deceive.

Just kidding. Maybe this will work for you.

+1
source

All Articles