gpt4 book ai didi

c++ - 如何使用 Excel 2007 SDK 在 C++ 中强制 xlTypeNum 加倍

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:28 24 4
gpt4 key购买 nike

好吧,我正在尝试通过开发 Excel 加载项来实现自己的目标。我正在尝试使用 Excel 2007 SDK 中的示例代码作为指南的小函数。我在尝试在 Excel 中显示 double 类型数据时遇到困难。假设在执行示例代码时 UDF 被调用 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;
}

最佳答案

看起来您将该值强制转换为 xltypeNum 但随后采用整数值,其中 d = xlt.val.w 而不是 d = xlt.val.num

关于c++ - 如何使用 Excel 2007 SDK 在 C++ 中强制 xlTypeNum 加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8791003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com