您好,
解决方案步骤:
1.给多个单元格设置Tag
- private void Form1_Load(object sender, EventArgs e)
- {
- FarPoint.Win.Spread.SheetView sv;
- sv = fpSpread1.ActiveSheet;
- sv.AddCustomFunction((new CubeFunctionInfo()));
- sv.SetFormula(1, 1, "CUBE(4,\"cell1\")");
- sv.SetFormula(2, 2, "CUBE(4,\"cell2\")");
- sv.SetTag(1, 1, "cell1");
- sv.SetTag(2, 2, "cell2");
- }
复制代码
2.在增加行列的时候,根据Tag取到新的位置
- private void button1_Click(object sender, EventArgs e)
- {
- this.fpSpread1.ActiveSheet.Rows.Add(1, 1);
- FarPoint.Win.Spread.Cell range1 = this.fpSpread1.ActiveSheet.Cells["cell1"];
- FarPoint.Win.Spread.Cell range2 = this.fpSpread1.ActiveSheet.Cells["cell2"];
- }
复制代码
3.调用的时候,通过参数,取到单元格的Tag
- public class CubeFunctionInfo : FarPoint.CalcEngine.FunctionInfo
- {
- public override string Name { get { return "CUBE"; } }
- public override int MinArgs { get { return 1; } }
- public override int MaxArgs { get { return 2; } }
- public override object Evaluate(object[] args)
- {
- //args[1] = ??
- double num = FarPoint.CalcEngine.CalcConvert.ToDouble(args[0]);
- return num * num * num;
- }
- }
复制代码
需要的注意的是:
您需要通过代码来维护一个自定义公式和位置的关系。这个需要一定的工作量。
希望可以帮助到您。 |