撰寫了一個自定義函式 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;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/12729.html
