//when the following line encounters a reference to
//an empty cell, the method returns #VALUE
''''double val = dataRange [0];返回值''''
[ExcelFunction(IsMacroType = true)]
public static object getVal([ExcelArgument(AllowReference = true)] double[] dataRange)
通过将函数的参数声明为double
(或double[]
),只允许您使用有效的double
值。
如果需要检查特殊值,例如ExcelEmpty
,则需要将函数的参数声明为object
(或object[]
)。
例如
[ExcelFunction(IsMacroType = true)]
public static object getVal([ExcelArgument(AllowReference = true)] object[] dataRange)
{
if (dataRange[0] == ExcelEmpty.Value)
{
// ...
}
// ...
}
[如果您希望通过ExcelReference
获取值,则将输入参数声明为object
,并检查它是否为ExcelReference
。
例如
[ExcelFunction(IsMacroType = true)]
public static object getVal([ExcelArgument(AllowReference = true)] object input)
{
if (input is ExcelReference reference)
{
// ...
var value = reference.GetValue();
// ...
}
// ...
}