如何编写具有可变数量参数的Excel加载项函数(例如:MAX,MIN …)

我正在使用Microsoft的开发框架(Excel 2010)在C ++中编写Excel加载项。

我想知道是否有可能用c + +写一个excel函数,有MAX,MIN,AVERAGE …

提前致谢。

假设你正在编码到XLL接口,那么AFAIK处理可变数量参数的唯一方法是将每个参数依次声明为你想要处理的最大数(受Excel版本限制),然后检查哪些缺失。

Excel加载项是作为COM对象构build的,对吧?

你有没有尝试在COM接口定义上使用[vararg]属性 ?

这是一个使用http://xll.codeplex.com处理多达16个参数的例子。

 // 16 LPOPERs #define XLL_LPOPERSX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX \ XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX XLL_LPOPERX static AddInX xai_functional_args( FunctionX(XLL_LPOPERSX, _T("?xll_functional_args"), _T("FUNCTIONAL.ARGS")) .Arg(XLL_LPOPERSX, _T("Arg1, ..."), _T("are a numeric arguments or NA() to indicate a missing argument.")) .Category(CATEGORY) .FunctionHelp(_T("Return an array for the second argument to FUNCTIONAL.BIND.")) .Documentation( _T("Non numeric arguments will not be bound.") ) ); LPOPER WINAPI xll_functional_args(LPOPERX px) { #pragma XLLEXPORT static OPER o; o.resize(0,0); for (LPOPERX* ppx = &px; (*ppx)->xltype != xltypeMissing && ppx - &px < 16; ++ppx) { o.push_back(**ppx); } o.resize(1, o.size()); return &o; }