简体   繁体   English

如何从XLL函数返回数组

[英]How to return array from XLL function

I am new in writing XLL, Anyone knows how to return a 6x1 array to Excel ? 我是新写的XLL,任何人都知道如何将6x1数组返回Excel?

The following is my function (some codes came from other post): 以下是我的功能(一些代码来自其他帖子):

__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] Currently I read the codes from XLL RETURN ARRAY and review my code, it can compile but returns 0 ... [2013-02-23]目前我从XLL RETURN ARRAY读取代码并查看我的代码,它可以编译但返回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;
} 

I can print an 1X2 array in Excel worksheet now, the following is my code. 我现在可以在Excel工作表中打印1X2数组,以下是我的代码。

**use Func signature type U **使用Func签名类型U.

1.select one row and two columns 1.选择一行两列

2.Type command =GetArray() in first cell 2.在第一个单元格中键入command = GetArray()

3.Ctrl + shift + enter 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;
}

Maybe http://xll.codplex.com can help you solve your problem, but as other people that are trying to help you, your code seems pretty far from shore. 也许http://xll.codplex.com可以帮助您解决问题,但正如其他人试图帮助您,您的代码似乎离岸很远。

On ne découvre pas de terre nouvelle sans consentir à perdre de vue, d'abord et longtemps, tout rivage. 在nedécouvarepas de terre nouvelle sansconsentiràperdrede vue,d'abord et longtemps,tout rivage。

Just kidding. 开玩笑。 Maybe that will work for you. 也许这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM