最近公司用报表
有个需求是做一个动态的表头 有点难度了 搜了好久 在阿泰的文章里找到了答案
如果实现这个动态列表呢
水晶报表里有离散值设置     通过公式可以来解决这个问题 通过参数来解决表头问题
  

  //使用报表对象加载报表
            ReportDocument myReport = new ReportDocument();
            string reportPath = Application.StartupPath + "/cp1.rpt";// Server.MapPath("~/app_data/crystalreport1.rpt");
            myReport.Load(reportPath);

            DataDefinition dataDefinition = myReport.DataDefinition;


   string[] Text4formularFields = new string[] { "{Employee.EmployeeID}", "{Employee.EmployeeName}", "{Employee.ProductName}" };
            FormulaFieldDefinitions formularFields = dataDefinition.FormulaFields;
            formularFields[0].Text = Text4formularFields[0];
            formularFields[1].Text = Text4formularFields[1];
            formularFields[2].Text = Text4formularFields[2];
这地方可以搞个循环来解决
以下是加参数 有点乱

 private ParameterFields GetParameterFields()
        {
            ParameterFields fields = new ParameterFields();

            //单位、部门、人员、日期范围参数
            fields.Add(this.CreateParameterField("title", "单位"));
            fields.Add(this.CreateParameterField("x1", "编号"));
            fields.Add(this.CreateParameterField("x2", "员工名"));
            fields.Add(this.CreateParameterField("x3", "产品名称"));
            //fields.Add(this.CreateParameterField("x2", "1"));
            //fields.Add(this.CreateParameterField("x3", "0"));
            //fields.Add(this.CreateParameterField("@empname", "人员"));
            //fields.Add(this.CreateParameterField("@daterange", "日期"));

            //返回
            return fields;
        }
        private ParameterField CreateParameterField(string FieldName, object FieldValue)
        {
            ParameterField field = new ParameterField();
            ParameterDiscreteValue pvalue = new ParameterDiscreteValue();

           
            pvalue.Value = FieldValue;
            field.Name = FieldName;
            field.CurrentValues.Add(pvalue);
            field.AllowCustomValues = false;

            //返回参数字段
            return field;
        }

posted on 2011-08-31 14:57 sanmao 阅读(475) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜