例子如下:
创建自定义函数
- public class GetAreaOfTriangleBySidelength : FarPoint.CalcEngine.FunctionInfo
- {
- public override object Evaluate(object[] args)
- {
- double a = CalcConvert.ToDouble(args[0]);
- double b = CalcConvert.ToDouble(args[1]);
- double c = CalcConvert.ToDouble(args[2]);
- double p = (a + b + c) / 2.0;
- double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
- return s;
- }
- public override int MaxArgs
- {
- get { return int.MaxValue; }
- }
- public override int MinArgs
- {
- get { return 0; }
- }
- public override string Name
- {
- get { return "AreaOfTriangle"; }
- }
- }
复制代码 使用自定义函数
- this.fpSpread1.ActiveSheet.AddCustomFunction(new GetAreaOfTriangleBySidelength());
- this.fpSpread1.ActiveSheet.Cells[0, 0].Value = 3;
- this.fpSpread1.ActiveSheet.Cells[1, 0].Value = 4;
- this.fpSpread1.ActiveSheet.Cells[2, 0].Value = 5;
- this.fpSpread1.ActiveSheet.SetFormula(3, 3, "AreaOfTriangle(A1,A2,A3)");
复制代码 |