sakeryu 你好,
可以通过 SelectChange 事件实现该功能,请参考代码:- private void Form1_Load(object sender, EventArgs e)
- {
- this.fpSpread1.Sheets[0].ColumnCount = 10;
- this.fpSpread1.Sheets[0].RowCount = 11;
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- this.fpSpread1.Sheets[0].Cells[i, j].Text = "1";
- }
- }
- this.fpSpread1.Sheets[0].Cells[10, 0].Text = "Sum:";
- this.fpSpread1.Sheets[0].Rows[10].Label = "统计";
- this.fpSpread1.Sheets[0].FrozenTrailingRowCount = 1;
- }
- private void fpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
- {
- string rowStarLabel = e.Range.Row.ToString();
- string rowEndLabel = (e.Range.Row + e.Range.RowCount-1).ToString();
- string colStarLabel = this.fpSpread1.Sheets[0].Columns[e.Range.Column].Label;
- string colEndLabel = this.fpSpread1.Sheets[0].Columns[e.Range.Column + e.Range.ColumnCount-1].Label;
- string formula ="SUM("+ colStarLabel + rowStarLabel+":" + colEndLabel + rowEndLabel+")";
- this.fpSpread1.Sheets[0].Cells[10, 1].Formula = formula;
- }
复制代码 |