应该是在拼接公式时有点不准确,你可以测试一下这段代码:
- private void fpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
- {
- string rowStarLabel = (e.Range.Row+1).ToString();
- string rowEndLabel = (e.Range.Row + e.Range.RowCount).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 + ")";
- FarPoint.Win.Spread.SheetView sheetview = new FarPoint.Win.Spread.SheetView();
- sheetview.RowCount = fpSpread1.ActiveSheet.GetSelection(0).RowCount + 1;
- sheetview.ColumnCount = fpSpread1.ActiveSheet.GetSelection(0).ColumnCount;
- fpSpread1.ActiveSheet.ClipboardCopy();
- sheetview.ClipboardPaste();
- for (int i = 0; i < sheetview.Columns.Count; i++)
- {
- sheetview.Columns[i].ResetCellType();
- }
-
- FarPoint.Win.Spread.CellType.NumberCellType numObj = new FarPoint.Win.Spread.CellType.NumberCellType();
- sheetview.Cells[sheetview.RowCount - 1, 0].CellType = numObj;
- sheetview.Cells[sheetview.RowCount - 1, 0].Formula = formula;
- textBox1.Text = sheetview.Cells[sheetview.RowCount - 1, 0].Text;
- }
复制代码 |