回复 2楼iceman的帖子
问题2,Spread 自定义公式方法如下:
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- gcSpreadSheet1.ActiveSheet.AddCustomFunction(new AverageFunctionInfo());
- gcSpreadSheet1.ActiveSheet.Cells[0, 0].Value = 1;
- gcSpreadSheet1.ActiveSheet.Cells[0, 1].Value = 2;
- gcSpreadSheet1.ActiveSheet.Cells[0, 2].Value = 3;
- gcSpreadSheet1.ActiveSheet.Cells[0, 3].Value = 4;
- gcSpreadSheet1.ActiveSheet.SetFormula(0, 4, "MyAverage(A1,B1,C1,D1)");
- }
- }
- [Serializable]
- public class AverageFunctionInfo : CalcFunction
- {
- 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 = (int)(args[0]);
- int X1 = (int)(args[1]);
- int X2 = (int)(args[2]);
- int X3 = (int)(args[3]);
- return ((X1 - X / X) <= 20 && ((X2 - X) / X) <= 20 && ((X3 - X) / X) <= 20);
- }
- }
复制代码 |