各位大侠请教:
我现在在一个项目中用FPSpread的时候,用户希望在选中多个单元格之后自动计算出单元格中数字之和(所有单元格中只有数字类型),
之前尝试过如下代码:
int sum = 0;
int startrow = this.fpSpread1.ActiveSheet.ActiveCell.Row.Index;
int startcolumn = this.fpSpread1.ActiveSheet.ActiveCell.Column.Index;
int rowlen = this.fpSpread1.ActiveSheet.GetSelection(0).RowCount;
int columnlen = this.fpSpread1.ActiveSheet.GetSelection(0).ColumnCount;
for (int i = 0; i < rowlen; i++) {
for (int j = 0; j < columnlen; j++) {
if (this.fpSpread1.ActiveSheet.Cells[startrow + i, startcolumn + j].Value != null || Convert.ToInt32(this.fpSpread1.ActiveSheet.Cells[startrow + i, startcolumn + j].Value) != 0)
{
sum += Convert.ToInt32(this.fpSpread1.ActiveSheet.Cells[startrow + i, startcolumn + j].Value);
}
}
}
但是这样计算出来的结果是不正确的,哪位高手援助下啊
跪求答案...
在线等... |
|