|
public class Class1
{
[ExcelFunction(Description = "用于单元格计算", Category = "C#自定义函数")]
public static double Js(string str)//用于EXCEL自定义函数
{
if (str.Length > 0)
{
Regex r = new Regex(@"\[(.+?)\]", RegexOptions.Multiline);
string st = r.Replace(str, "");
var js = new DataTable().Compute(st, ""); //表达式计算
return Convert.ToDouble(js);
}
else
{
return 0;
}
}
[ExcelFunction(Description = "计算两列相乘之和", Category = "C#自定义函数")]
public static double newsum(double[]arr,double[]brr)
{
double js=0;
for(int i=0;i<arr.GetLength(0);i++)
{
if(arr[i]>0&&brr[i]>0)
{
js += arr[i] * brr[i];
}
}
return js;
}
} |
|