找回密码
 立即注册

QQ登录

只需一步,快速开始

whpengwei

高级会员

19

主题

42

帖子

1709

积分

高级会员

积分
1709

活字格认证

whpengwei
高级会员   /  发表于:2013-1-28 15:55  /   查看:5523  /  回复:1
版主你好,我在使用MultiRow 合计的时候碰到了个问题
我的 数量吨数的数据是 3位小数,在设置单元格样式的时候2位小数(客户要求),最后一行有个合计行,也是2位小数,但是问题是,最后的合计他计算出来的数据是按我的源数据计算后,保留的2位小数,不是直接按显示在单元格上的2位小数的合计数,造成了 合计数字与上面的数字不相等。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

1 个回复

倒序浏览
barrylei
中级会员   /  发表于:2013-1-28 17:22:00
沙发
为了实现你的用例,需要实现ICalculation接口,然后把你的实现赋给SummaryCell的Calculation属性。

  1.     public sealed partial class Template1 : Template
  2.     {
  3.         public Template1()
  4.         {
  5.             InitializeComponent();
  6.             this.YourCellName.ValueType = typeof(double); //YourCellName 是你要计算的那个Cell
  7.             this.summaryCell1.Calculation = new MyCalculate();
  8.             
  9.         }
  10.     }
  11.     public class MyCalculate : ICalculation
  12.     {
  13.         public object Calculate(CalculationContext context)
  14.         {
  15.             double result = 0.0;
  16.             if (context.Scope == CellScope.ColumnFooter)
  17.             {
  18.                 object temp = null;
  19.                 for (int i = 0; i < context.GcMultiRow.RowCount; i++)
  20.                 {
  21.                     temp = context.GcMultiRow.GetValue(i, "YourCellName");
  22.                     if (temp != null && temp is double)
  23.                     {
  24.                         result += Math.Round((double)temp,2);
  25.                     }
  26.                 }
  27.             }
  28.             return result;
  29.         }

  30.         public object Clone()
  31.         {
  32.             return new MyCalculate();
  33.         }
  34.     }
复制代码


MultiRow缺省提供的SummaryCell都是以Cell的Value来计算的,为了实现你的用例,通过Math.Round函数先四舍五入到2位,然后再一个个加去起来。实现的思路就是这样,可能你要根据你的业务需求作适当的修改。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部