예제 #1
0
        private string SpellAddTotalScript()
        {
            StringBuilder builder    = new StringBuilder("\n");
            TotalField    totalField = null;

            foreach (string name in this._totalFieldNameList)
            {
                totalField = (TotalField)this.TotalFieldList[name];

                if (totalField is CalculatedField)
                {
                    /*在数据透视表中添加计算总计。使用 AddCalculatedTotal 方法创建基于数据透视表中定义的总计的自定义总计。计算总计返回一个 PivotTotal 对象。
                     * expression.AddCalculatedTotal(Name, Caption, Expression, SolveOrder)
                     * expression      必需。该表达式返回一个 PivotView 对象。
                     * Name     String 类型,必需。用于在 PivotTotals 集合中标识新计算总计。该参数在 PivotTotals 集合中必须唯一。长度必须在 1 到 50 个字符之间。
                     * Caption     String 类型,必需。用于在数据透视表用户界面中标识新计算总计。
                     * Expression     String 类型,必需。该表达式用于计算新计算总计。必须为访问数据所用的 OLE DB 提供者的有效多维表达式 (MDX) 语句。
                     * SolveOrder     Long 类型,可选。表示在刷新数据透视表时新计算总计的求解次序。如果创建的计算总计取决于前面创建的计算总计,则 SolveOrder 参数非常有用。
                     * */
                    builder.Append(string.Format("	{0}.ActiveView.DataAxis.InsertTotal ( {0}.ActiveView.AddCalculatedTotal ( \"{1}\", \"{2}\",\"{3}\" ) )\n",
                                                 "Document.Forms(0)." + this.PivotTableName,
                                                 ((CalculatedField)totalField).FieldName,
                                                 ((CalculatedField)totalField).Caption,
                                                 ((CalculatedField)totalField).Expression
                                                 ));
                }

                if (!(totalField is CalculatedField))
                {
                    builder.Append(string.Format("		{0}.ActiveView.DataAxis.InsertTotal( {0}.ActiveView.AddTotal(\"{1}\", {0}.ActiveView.Fieldsets(\"{2}\").Fields(0), {0}.Constants.{3}) )\n",
                                                 "Document.Forms(0)." + this.PivotTableName,
                                                 totalField.Caption,
                                                 totalField.FieldName,
                                                 totalField.FunctionType));
                }

                foreach (string key in totalField.Attributes.Keys)
                {
                    builder.Append(string.Format("		{0}.ActiveView.Totals(\"{1}\").{2} = \"{3}\"\n\n",
                                                 "Document.Forms(0)." + this.PivotTableName,
                                                 totalField.Caption,
                                                 key,
                                                 totalField.Attributes[key].ToString()));
                }
            }

            return(builder.ToString());
        }
예제 #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                string[] attrs = ((string)value).Split(new char[] { ',' });
                string[] v     = null;

                TotalField field = new TotalField(attrs[0], attrs[1], attrs[2]);

                for (int i = 3; i < attrs.Length; i++)
                {
                    v = attrs[i].Split('=');
                    field.Attributes.Add(v[0], v[1]);
                }

                return(field);
            }
            return(base.ConvertFrom(context, culture, value));
        }