Return two dimensional array to excel from a c++ xll, the come back

后端 未结 1 1295
粉色の甜心
粉色の甜心 2021-01-22 04:40

First of all I know that the question was already asked here :

return multi dimension array to excel from c++ xll

I have tried to revive the subject, without suc

相关标签:
1条回答
  • 2021-01-22 04:57

    A simple example returning a 5*5 matrix. Don't forget to free the allocated array via the xlAutoFree12 function.

    __declspec(dllexport) LPXLOPER12 WINAPI Get2DArray(void)
    {   
        static XLOPER12 xlArray;
        int rows = 5;
        int cols = 5;
        xlArray.xltype = xltypeMulti | xlbitDLLFree;
        xlArray.val.array.rows = rows;
        xlArray.val.array.columns = cols;
        xlArray.val.array.lparray = reinterpret_cast<LPXLOPER12>(::malloc(rows * cols * sizeof(XLOPER12)));
        for (int r=0;r<rows;r++)
        {
                for (int c=0;c<cols;c++)
                {
                    XLOPER12* var = xlArray.val.array.lparray + ((r* cols) + c);
                    var->xltype = xltypeNum;
                    var->val.num = r*c;
                }
        }
        return &xlArray;
    }
    
    0 讨论(0)
提交回复
热议问题