问题描述
- 如何在一个XLL+ 程序中call另外一个XLL+中的函数
-
大家好,我的问题是,如何在一个XLL+程序中call另外一个XLL+中的函数。我已经编好并运行成功了一个XLL+ user defined function,函数为sum1,在excel中加入这个add in以后,可以用sum1函数进行运算。现在我开始编写另外一个XLL,e.g.sum2,而在sum2程序中我想直接call sum1函数,然后由于两个函数在两个不同的XLL中,不能直接call,因此需要进行一定的处理才行。请问各位大牛有碰到过这种情况吗?有什么好的代码或者方法可以使用吗?
在网上查了一些,查到下列代码,是用evaluate和UDF function做的,但是这个貌似只适用于visual studio 2005,不适用于2012, 在Visual studio 2012下运行不出正确的结果,会显示#Name error
请各位大牛指导和指正!
// Function: CalDaysInYear2
// Purpose: Calls a function in another XLL//{{XLP_SRC(CalDaysInYear2)
// NOTE - the FunctionWizard will add and remove mapping code here.
// DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(CalDaysInYear2, "RI", "CalDaysInYear2",
"DayCount", "Date & Time", "Calls a function in another XLL,"
" which returns number of days in a year according to the"
" day count", "Day count convention00", "appscope=1",
1)extern "C" __declspec( dllexport )
LPXLOPER CalDaysInYear2(short DayCount)
{
XLL_FIX_STATE;
CXlOper xloResult;
//}}XLP_SRCstatic int xlfEvaluate = 257; static int xlUDF = 255; CXlOper xloName, xloRef; int rc = 0; xloName = "CalDaysInYear"; if (!rc) rc = xloRef.Excel(xlfEvaluate, 1, &xloName); if (!rc) rc = xloResult.Excel(xlUDF, 2, &xloRef, &CXlOper(DayCount, 0)); return xloResult.Ret();
}