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

亡梦爱人 提交于 2019-12-02 01:40:11

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!