嗯,我正在尝试开发一个Excel外接程序。我正在尝试使用Excel2007SDK中的示例代码作为指南的小函数。我尝试在Excel中显示双精度类型数据时遇到困难。假设在执行示例代码时调用DisplayDouble(),并使用实数类型数据的参数(如DisplayDouble( 12.3 ) )进行调用,则样例代码可以工作。如果我尝试使用引用单元格的实数类型数据的参数,例如DisplayDouble( A1 ),其中Excel工作表中的单元格A1的值为12.3,则样例代码不起作用
你可以在这一段下面看到示例代码。任何提示都将帮助我沿着学习阶梯前进。
_declspec(dllexport) LPXLOPER12 WINAPI DisplayDouble (LPXLOPER12 n)
{
static XLOPER12 xResult;
XLOPER12 xlt;
int error = -1;
double d;
switch (n->xltype)
{
case xltypeNum:
d = (double)n->val.num;
if (max < 0)
error = xlerrValue;
xResult.xltype = xltypeNum;
xResult.val.num = d;
break;
case xltypeSRef:
error = Excel12f(xlCoerce, &xlt, 2, n, TempNum12(xltypeNum));
if (!error)
{
error = -1;
d = xlt.val.w;
xResult.xltype = xltypeNum;
xResult.val.num = d;
}
Excel12f(xlFree, 0, 1, &xlt);
break;
default:
error = xlerrValue;
break;
}
if ( error != - 1 )
{
xResult.xltype = xltypeErr;
xResult.val.err = error;
}
//Word of caution - returning static XLOPERs/XLOPER12s is not thread safe
//for UDFs declared as thread safe, use alternate memory allocation mechanisms
return(LPXLOPER12) &xResult;
}发布于 2012-02-07 19:28:12
看起来您强制将值转换为xltypeNum,但随后使用d= xlt.val.w而不是d= xlt.val.num获取整数值
https://stackoverflow.com/questions/8791003
复制相似问题