你好,我在数据源上设置字段数据类型后公式起到作用,
- this.FpSpread1.Sheets[0].DataAutoCellTypes = false;
- //设置数据源字段数据类型.
- DataTable dt = new DataTable();
- //第一列设定为 String 类型,设置 AVERAGE(A1:C1) 后此列不会参与计算.
- dt.Columns.Add("列1", typeof(System.String));
- //其余列列设定为 Double 类型,设置 AVERAGE(A1:C1) 参加计算部分.
- dt.Columns.Add("列2", typeof(System.Double));
- dt.Columns.Add("列3", typeof(System.Double));
- dt.Columns.Add("列4", typeof(System.Double));
- DataRow dr0 = dt.NewRow();
- dr0["列1"] = 11.000;
- dr0["列2"] = 2;
- dr0["列3"] = 3;
- dt.Rows.Add(dr0);
- FpSpread1.DataSource = dt;
- FpSpread1.DataBind();
- DoubleCellType db = new DoubleCellType();
- db.DecimalDigits = 3;
- db.FixedPoint = true;
- FpSpread1.ActiveSheetView.Cells[0, 0].CellType = db;
- FpSpread1.ActiveSheetView.Cells[0, 1].CellType = db;
- FpSpread1.ActiveSheetView.Cells[0, 2].CellType = db;
- FpSpread1.ActiveSheetView.Cells[0, 3].CellType = db;
- FpSpread1.ClientAutoCalculation = true;
- FpSpread1.Sheets[0].SetFormula(0, 3, "AVERAGE(A1:C1)");
复制代码 效果图:
png
如果以上仍然不符合你的需求,那么请你发 Demo 过来,我们继续交流:share: ~ |