简体   繁体   中英

Returning array in Excel XLL

I'm use Excel 2010 and the Excel 2010 XLL SDK. I try with this function:

__declspec(dllexport) LPXLOPER12 WINAPI dfutil(void)
{     
        static XLOPER12 xlArray;
        XLOPER12 xlValues[4];
        int i;
        double z = 3.1456;
        for (i = 0; i < 4; ++i)
        {
        xlValues[i].val.num = i*z;
        xlValues[i].xltype = xltypeNum;
        }

        xlArray.xltype = xltypeMulti;
        xlArray.val.array.lparray = xlValues;//&xlValues[0];
        xlArray.val.array.rows = 1;
        xlArray.val.array.columns = 4;
        return (LPXLOPER12) &xlArray;
}

Definition:

{
      L"dfutil",
      L"QU",        
      L"dfutil",
      L"",
      L"1",
      L"SimpleXll2007",
      L"",                  
      L"",                  
      L"ReturnArray function help",
      L"",
      L""
},

When xlValues array size is 4 then returns to excel 4 values, but the 3rd value is TRUE (??). When xlValues array size is 10 it returns to Excel a #NUM error. What is the right way to return array to Excel?

PS I use such template this article http://blogs.msdn.com/b/andreww/archive/2007/12/09/building-an-excel-xll-in-cc-with-vs-2008.aspx

You need to make xlValues static too. Using https://xll.codeplex.com will make your life easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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