简体   繁体   English

从Excel2000单元使用ExcelApp.Caller

[英]Using ExcelApp.Caller from the Excel2000 unit

I'm writing an Excel-addin that implements custom Excel functions using XLAutomationAddin. 我正在编写一个使用XLAutomationAddin实现自定义Excel函数的Excel插件。

In the Excel2000 unit you can use the ExcelApplication.Caller property to ascertain the ExcelRange that called your custom function. 在Excel2000单元中,可以使用ExcelApplication.Caller属性来确定调用自定义函数的ExcelRange。

However the definition of the Excel2000.pas typelib says that I need to use 但是Excel2000.pas typelib的定义说我需要使用

property ExcelApplication.Caller[Index: OleVariant; lcid: Integer]: OleVariant;

No matter what I try I cannot get this to work because Excel keeps on refusing any parameters that I put in. 不管我尝试什么,我都无法使它正常工作,因为Excel一直拒绝输入的任何参数。
I know I can input 0 OR LOCALE_USER_DEFAULT into lcid , but what does Excel want for the Index parameter? 我知道我可以在lcid输入0 OR LOCALE_USER_DEFAULT ,但是Excel对Index参数有什么要求?

The solution is to cast the ExcelApplication into an OleVariant. 解决方案是将ExcelApplication转换为OleVariant。

Like so: 像这样:

unit ExcelHelper;
....
implementation

var
  Excel: ExcelApplication;  {global var in unit}

function Caller: ExcelRange;
var
  ExcelAsVar: OleVariant;
begin
  try
    ExcelAsVar:= Excel.Application;
    Result:= IUnkown(ExcelAsVar.Caller) as ExcelRange;
  except 
    Result:= nil;
  end; {try}
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM