请教XLL中的xloper 中xa.val.sref.ref.rwFirst 返回值问题,难度很有挑战.
编写了一个自定义函数 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;