[英]How to reference a range of cells in UDF
c#, ExcelDNA, in my UDF, I want to pass a range of cells, MyUDF(A1:A2) c#,ExcelDNA,在我的UDF中,我想传递一系列单元格,MyUDF(A1:A2)
I tried MyUDF(object param1), if I type in myUDF(A1:A2), the MyUDF is never called I also tried MyUDF(string param1), MyUDF(string[] param1) neither works. 我尝试了MyUDF(对象param1),如果我输入myUDF(A1:A2),MyUDF永远不会被调用我也试过MyUDF(字符串param1),MyUDF(string [] param1)都不起作用。
What type of the parameter should be? 应该是什么类型的参数? thanks
谢谢
The format public static object MyUDF(object param1) {...}
should work fine, and your formula with =MyUDF(A1:A2)
will pass in an object array with the values in those cells. 格式
public static object MyUDF(object param1) {...}
应该可以正常工作,并且带有=MyUDF(A1:A2)
公式将在具有这些单元格中的值的对象数组中传递。
If you want to allow the argument to be a reference to the passed in range, you'd declare it as 如果要允许参数作为传入范围的引用,则将其声明为
public static object MyUDF(
[ExcelArgument(AllowReference=true)] object param1) {...}
The extra attribute tells Excel to pass in the actual reference when called as =MyUDF(A1:A2)
- the reference will be of type ExcelDna.Integration.ExcelReference
, from where you can get the values or make further calls to the Excel API to get the address or anything. 额外属性告诉Excel在调用
=MyUDF(A1:A2)
时传入实际引用 - 引用的类型为ExcelDna.Integration.ExcelReference
,您可以从中获取值或进一步调用Excel API得到地址或任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.