简体   繁体   English

如何加速.xll 函数中的数组处理?

[英]How to speed up array processing in .xll function?

I want to get equal speed of my function VLOOKUP2 and standard VLOOKUP in Excel.我想在 Excel 中获得我的函数 VLOOKUP2 和标准 VLOOKUP 的相同速度。 But getting an array of cells in my VLOOKUP2 function is already longer than the speed of the standard VLOOKUP function in Excel.但是在我的 VLOOKUP2 函数中获取单元格数组的速度已经超过 Excel 中标准 VLOOKUP 函数的速度。

I watched examples from Excel 2013 XLL SDK (С) and found nothing useful for myself.我观看了 Excel 2013 XLL SDK (С) 中的示例,发现对我自己没有任何用处。 I used two solutions:我使用了两种解决方案:

1.Getting the OPER12 array using the Q parameter in the HelpRegister12 function 1.使用HelpRegister12函数中的Q参数获取OPER12数组

int WINAPI xlAutoOpen(void)
    {
        HelpRegister12(L"VLOOKUP2", L"QQQQ$"...)
    }

extern "C" __declspec(dllexport) LPXLOPER12  WINAPI VLOOKUP2(LPXLOPER12 XLOP1, LPXLOPER12 XLOP2, LPXLOPER12 XLOP3)
    {
    '''
    }

2.Getting the XLOPER12 array using the U parameter in the HelpRegister12 function 2.使用HelpRegister12函数中的U参数获取XLOPER12数组

int WINAPI xlAutoOpen(void)
    {
        HelpRegister12(L"VLOOKUP2", L"UUUU$"...)
    }

extern "C" __declspec(dllexport) LPXLOPER12  WINAPI VLOOKUP2(LPXLOPER12 XLOP1, LPXLOPER12 XLOP2, LPXLOPER12 XLOP3)
    {
...
LPXLOPER12 FAR *ppxArg; // Pointer to the argument being processed 
ppxArg = &XLOP1;
XLOPER12 xMulti;        // Argument coerced to xltypeMulti 
...
if (xlretUncalced == Excel12(xlCoerce, &xMulti, 2,(LPXLOPER12) *ppxArg, TempInt12(xltypeMulti)))
            {
                //
                // That coerce might have failed due to an 
                // uncalced cell, in which case, we need to 
                // return immediately. Microsoft Excel will
                // call us again in a moment after that cell
                // has been calced.
                //
                return 0;
            }
...

    }

All two solutions are slower than the standard VLOOKUP function in Excel.所有两种解决方案都比 Excel 中的标准 VLOOKUP 函数慢。

Is it possible to get a link to a separate array element (cell) without using the entire array and without using the Excel12 function (xlCoerce, ...)?是否可以在不使用整个数组且不使用 Excel12 函数(xlCoerce,...)的情况下获得指向单独数组元素(单元格)的链接? for example for the second solution:例如对于第二个解决方案:

    LPXLOPER12 ppxArgTmp;
    ppxArgTmp = &(*ppxArg1)->val.array.lparray[x];

? ?

How to speed up getting an array?如何加快获取数组的速度? I don't need all the elements, I need the elements until the first match.我不需要所有元素,我需要元素直到第一次匹配。

Why is the standard VLOOKUP function faster?为什么标准的 VLOOKUP 函数更快?

Regarding your question to access cells individually, yes it is possible, see below (arrays are row-major in excel):对于单独访问细胞你的问题,是有可能的,见下文(数组行主要在Excel中):

int row = ppxArg1->val.array.rows ;
int col = ppxArg1->val.array.columns ;

 for (int r=0;r<row ;r++)
      for (int c=0;c<col;c++)
        LPXLOPER12 cell =   ppxArg1->val.array.lparray + ((r* col) + c); //access each cells

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

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