예제 #1
0
        internal void LoadItems()
        {
            _items = new ExcelPivotTableFieldItemsCollection(this);
            if (Cache.DatabaseField == false)
            {
                return;
            }
            EPPlusReadOnlyList <object> cacheItems;

            if (Cache.Grouping == null)
            {
                cacheItems = Cache.SharedItems;
            }
            else
            {
                cacheItems = Cache.GroupItems;
            }

            foreach (XmlElement node in TopNode.SelectNodes("d:items//d:item", NameSpaceManager))
            {
                var item = new ExcelPivotTableFieldItem(node);
                if (item.X >= 0)
                {
                    item.Value = cacheItems[item.X];
                }
                _items.AddInternal(item);
            }
        }
예제 #2
0
        internal void UpdateGroupItems(ExcelPivotTableCacheField cacheField, bool addTypeDefault)
        {
            XmlElement itemsNode = CreateNode("d:items") as XmlElement;

            _items = new ExcelPivotTableFieldItemsCollection(this);
            itemsNode.RemoveAll();
            for (int x = 0; x < cacheField.GroupItems.Count; x++)
            {
                _items.AddInternal(new ExcelPivotTableFieldItem()
                {
                    X = x, Value = cacheField.GroupItems[x]
                });
            }
            if (addTypeDefault)
            {
                _items.AddInternal(new ExcelPivotTableFieldItem()
                {
                    Type = eItemType.Default
                });
            }
        }
예제 #3
0
        private void AddDateGrouping(eDateGroupBy groupBy, DateTime startDate, DateTime endDate, int groupInterval)
        {
            if (groupInterval < 1 || groupInterval >= Int16.MaxValue)
            {
                throw (new ArgumentOutOfRangeException("Group interval is out of range"));
            }
            if (groupInterval > 1 && groupBy != eDateGroupBy.Days)
            {
                throw (new ArgumentException("Group interval is can only be used when groupBy is Days"));
            }
            if (Cache.DatabaseField == false)
            {
                throw new InvalidOperationException("The field for grouping can not be a calculated field.");
            }
            ValidateGrouping();

            _items = null;

            bool firstField = true;
            var  fields     = _pivotTable.Fields.Count;

            //Seconds
            if ((groupBy & eDateGroupBy.Seconds) == eDateGroupBy.Seconds)
            {
                AddField(eDateGroupBy.Seconds, startDate, endDate, ref firstField);
            }
            //Minutes
            if ((groupBy & eDateGroupBy.Minutes) == eDateGroupBy.Minutes)
            {
                AddField(eDateGroupBy.Minutes, startDate, endDate, ref firstField);
            }
            //Hours
            if ((groupBy & eDateGroupBy.Hours) == eDateGroupBy.Hours)
            {
                AddField(eDateGroupBy.Hours, startDate, endDate, ref firstField);
            }
            //Days
            if ((groupBy & eDateGroupBy.Days) == eDateGroupBy.Days)
            {
                AddField(eDateGroupBy.Days, startDate, endDate, ref firstField, groupInterval);
            }
            //Month
            if ((groupBy & eDateGroupBy.Months) == eDateGroupBy.Months)
            {
                AddField(eDateGroupBy.Months, startDate, endDate, ref firstField);
            }
            //Quarters
            if ((groupBy & eDateGroupBy.Quarters) == eDateGroupBy.Quarters)
            {
                AddField(eDateGroupBy.Quarters, startDate, endDate, ref firstField);
            }
            //Years
            if ((groupBy & eDateGroupBy.Years) == eDateGroupBy.Years)
            {
                AddField(eDateGroupBy.Years, startDate, endDate, ref firstField);
            }

            if (fields > _pivotTable.Fields.Count)
            {
                _cacheField.SetXmlNodeString("d:fieldGroup/@par", (_pivotTable.Fields.Count - 1).ToString());
            }
            if (groupInterval != 1)
            {
                _cacheField.SetXmlNodeString("d:fieldGroup/d:rangePr/@groupInterval", groupInterval.ToString());
            }
            else
            {
                _cacheField.DeleteNode("d:fieldGroup/d:rangePr/@groupInterval");
            }
        }