回复 9楼风中人的帖子
理解您的需求包括两个问题:
1.自定义公式
2.自定义公式实现自动计算
以上均可以实现。
代码如下:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- return;
- }
- this.FpSpread1.ClientAutoCalculation = true;
- this.FpSpread1.ActiveSheetView.ColumnCount = 5;
- DefaultSheetDataModel dataModel = FpSpread1.ActiveSheetView.DataModel as FarPoint.Web.Spread.Model.DefaultSheetDataModel;
- if (dataModel != null)
- {
- dataModel.AddCustomFunction(new AverageFunctionInfo());
- }
- FpSpread1.ActiveSheetView.Cells[0, 0].Value = 1;
- FpSpread1.ActiveSheetView.Cells[0, 1].Value = 2;
- FpSpread1.ActiveSheetView.Cells[0, 2].Value = 3;
- FpSpread1.ActiveSheetView.Cells[0, 3].Value = 4;
- FpSpread1.ActiveSheetView.SetFormula(0, 4, "MyAverage(A1,B1,C1,D1)");
- }
- [Serializable]
- public class AverageFunctionInfo : FunctionInfo
- {
- public override string Name { get { return "MyAverage"; } }
- public override int MinArgs { get { return 1; } }
- public override int MaxArgs { get { return 4; } }
- public override object Evaluate(object[] args)
- {
- int X = CalcConvert.ToInt(args[0]);
- int X1= CalcConvert.ToInt(args[1]);
- int X2= CalcConvert.ToInt(args[2]);
- int X3= CalcConvert.ToInt(args[3]);
- return ((X1-X/X)<=20&&((X2-X)/X)<=20&&((X3-X)/X)<=20);
- }
- }
复制代码 |