internal ExcelPivotTableCacheField AddDateGroupField(ExcelPivotTableField field, eDateGroupBy groupBy, DateTime startDate, DateTime endDate, int interval)
        {
            ExcelPivotTableCacheField cacheField = CreateField(groupBy.ToString(), field.Index, false);

            cacheField.SetDateGroup(field, groupBy, startDate, endDate, interval);

            Fields.Add(cacheField);
            return(cacheField);
        }
Beispiel #2
0
        private ExcelPivotTableField AddField(eDateGroupBy groupBy, DateTime startDate, DateTime endDate, ref bool firstField, int interval)
        {
            if (firstField == false)
            {
                ExcelPivotTableField field = _pivotTable.Fields.AddDateGroupField(Index);

                XmlNode rowColFields;
                if (IsRowField)
                {
                    rowColFields = TopNode.SelectSingleNode("../../d:rowFields", NameSpaceManager);
                }
                else
                {
                    rowColFields = TopNode.SelectSingleNode("../../d:colFields", NameSpaceManager);
                }

                var index = 0;
                foreach (XmlElement rowfield in rowColFields.ChildNodes)
                {
                    if (int.TryParse(rowfield.GetAttribute("x"), out int fieldIndex))
                    {
                        if (_pivotTable.Fields[fieldIndex].BaseIndex == BaseIndex)
                        {
                            var newElement = rowColFields.OwnerDocument.CreateElement("field", ExcelPackage.schemaMain);
                            newElement.SetAttribute("x", field.Index.ToString());
                            rowColFields.InsertBefore(newElement, rowfield);
                            break;
                        }
                    }
                    index++;
                }

                var cacheRef = _pivotTable.CacheDefinition._cacheReference;
                field._cacheField = cacheRef.AddDateGroupField(field, groupBy, startDate, endDate, interval);
                UpdatePivotTableGroupItems(field, cacheRef, false);

                if (IsRowField)
                {
                    _pivotTable.RowFields.Insert(field, index);
                }
                else
                {
                    _pivotTable.ColumnFields.Insert(field, index);
                }

                return(field);
            }
            else
            {
                firstField = false;
                Compact    = false;
                _cacheField.SetDateGroup(this, groupBy, startDate, endDate, interval);
                UpdatePivotTableGroupItems(this, _pivotTable.CacheDefinition._cacheReference, true);
                return(this);
            }
        }