请教XLL中的xloper 中xa.val.sref.ref.rwFirst 返回值问题,难度很有挑战.

gyhong 2020-04-22 07:09:10
编写了一个自定义函数 myfunc(xa: lpXLOPER), 函数的返回值为xa的行号。

完成注册后,打开excel 使用时,如到了返回值不正常的情况:
=myfunc(A12), 返回值11,=myfunc(A15), 返回值14,参数为当前表的单元格时,返回值正确。
=myfunc(sheet2!A12), 返回值11,=myfunc(sheet2!A15), 返回值14,参数为其他表的单元格时,返回值均为653,返回值不是正确值。
不知为何 当参数为引用的其他表的单元格时,为何函数的返回值是错误的?








function myfunc(xa: lpXLOPER): lpxloper; stdcall;

var
tempxloper, xres, xSheetname: XLOPER;

begin

excelappa.Connect;
tempxloper.xltype := xltypenum;

tempxloper.val.num := xa.val.sref.ref.rwFirst;

Result := @tempxloper;
end;

function Register_Adjust20: integer;
var
s: Shortstring;
begin
Res.xltype := xltypeerr;
Res.val.err := xlerrvalue;
s := GetName;
pxModuleText.SetStr(s);
pxProcedure.SetStr('myfunc');

pxTypeText.SetStr('RP!');


// R Excel's XLOPER data structure
pxFunctionText.setStr('myfunc);
pxArgumentText.SetStr('strX');
pxMacrotype.SetNum(1);
pxCategory.SetStr(AddInCategory);

EResult := Excel4V(xlfregister, @res, 8,
[pxModuletext.thelpxloper,
pxProcedure.thelpxloper,
pxTypeText.thelpxloper,
pxFunctionText.thelpxloper,
pxArgumentText.thelpxloper,
pxMacroType.thelpxloper,
pxCategory.thelpxloper,
zlpxloper]);
asm pop sink;
end; // Never Remove
Result := trunc(res.val.num);
end;
...全文
45 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧