我正在尝试熟悉 Excel-DNA,但找不到有关如何遍历工作表单元格中选定范围的值的文档。因此,我将有一个用户定义的函数,该函数将一系列单元格作为参数,在这些单元格中我将拥有一些数据。然后我会遍历这个范围的单元格并对数据做一些事情。我怎样才能做这种基本的操作?我在 Visual Studio 中的代码可能看起来像这样。
using System;
using System.Collections.Generic;
using ExcelDna.Integration;
namespace myUDF
{
public static class Class1
{
[ExcelFunction(Name = "LoopArrayTester")]
public static List<double> LoopArrayTester(??? range)
{
List<double> list = new List<double>();
// loop through somehow the range in worksheet given
// somehow in the method signature
for(int i = 0; i < range.count; i++)
{
// get values of i'th cell in range and put it to list
// or something.
}
}
return list;
}
}
Run Code Online (Sandbox Code Playgroud)