示例#1
0
        internal ExcelPivotCacheDefinition(XmlNamespaceManager nsm, ExcelPivotTable pivotTable)
        {
            Relationship = pivotTable.Part.GetRelationshipsByType(ExcelPackage.schemaRelationships + "/pivotCacheDefinition").FirstOrDefault();
            var cacheDefinitionUri = UriHelper.ResolvePartUri(Relationship.SourceUri, Relationship.TargetUri);

            PivotTable = pivotTable;
            _wb        = pivotTable.WorkSheet.Workbook;
            _nsm       = nsm;
            var c = _wb._pivotTableCaches.Values.FirstOrDefault(x => x.PivotCaches.Exists(y => y.CacheDefinitionUri.OriginalString == cacheDefinitionUri.OriginalString));

            if (c == null)
            {
                var pck = pivotTable.WorkSheet._package.ZipPackage;
                if (_wb._pivotTableIds.ContainsKey(cacheDefinitionUri))
                {
                    var cid = _wb._pivotTableIds[cacheDefinitionUri];
                    _cacheReference = new PivotTableCacheInternal(_wb, cacheDefinitionUri, cid);
                    _wb.AddPivotTableCache(_cacheReference, false);
                }
                else
                {
                    throw new Exception("Internal error: Pivot table uri does not exist in package.");
                }
            }
            else
            {
                _cacheReference = c.PivotCaches.FirstOrDefault(x => x.CacheDefinitionUri.OriginalString == cacheDefinitionUri.OriginalString);
            }
            _cacheReference._pivotTables.Add(pivotTable);
        }
示例#2
0
        /// <summary>
        /// Add a new pivottable
        /// </summary>
        /// <param name="sheet">The worksheet</param>
        /// <param name="address">the address of the pivottable</param>
        /// <param name="pivotTableCache">The pivot table cache</param>
        /// <param name="name"></param>
        /// <param name="tblId"></param>
        internal ExcelPivotTable(ExcelWorksheet sheet, ExcelAddressBase address, PivotTableCacheInternal pivotTableCache, string name, int tblId) :
            base(sheet.NameSpaceManager)
        {
            CreatePivotTable(sheet, address, pivotTableCache.Fields.Count, name, tblId);

            CacheDefinition = new ExcelPivotCacheDefinition(sheet.NameSpaceManager, this, pivotTableCache);
            CacheId         = pivotTableCache.CacheId;

            LoadFields();
        }
示例#3
0
 internal ExcelPivotCacheDefinition(XmlNamespaceManager nsm, ExcelPivotTable pivotTable, ExcelRangeBase sourceAddress)
 {
     PivotTable      = pivotTable;
     _wb             = PivotTable.WorkSheet.Workbook;
     _nsm            = nsm;
     _cacheReference = new PivotTableCacheInternal(nsm, _wb);
     _cacheReference.InitNew(pivotTable, sourceAddress, null);
     _wb.AddPivotTableCache(_cacheReference);
     Relationship = pivotTable.Part.CreateRelationship(UriHelper.ResolvePartUri(pivotTable.PivotTableUri, _cacheReference.CacheDefinitionUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotCacheDefinition");
 }
示例#4
0
 internal ExcelPivotTableCacheField(XmlNamespaceManager nsm, XmlNode topNode, PivotTableCacheInternal cache, int index) : base(nsm, topNode)
 {
     _cache = cache;
     Index  = index;
     SetCacheFieldNode();
     if (NumFmtId.HasValue)
     {
         var styles = cache._wb.Styles;
         var ix     = styles.NumberFormats.FindIndexById(NumFmtId.Value.ToString(CultureInfo.InvariantCulture));
         if (ix >= 0)
         {
             Format = styles.NumberFormats[ix].Format;
         }
     }
 }
示例#5
0
        internal ExcelPivotCacheDefinition(XmlNamespaceManager nsm, ExcelPivotTable pivotTable, PivotTableCacheInternal cache)
        {
            PivotTable = pivotTable;
            _wb        = PivotTable.WorkSheet.Workbook;
            _nsm       = nsm;
            if (cache._wb != _wb)
            {
                throw (new InvalidOperationException("The pivot table and the cache must be in the same workbook."));
            }

            _cacheReference = cache;
            _cacheReference._pivotTables.Add(pivotTable);

            var rel = pivotTable.Part.CreateRelationship(UriHelper.ResolvePartUri(pivotTable.PivotTableUri, _cacheReference.CacheDefinitionUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotCacheDefinition");
        }
示例#6
0
        private static void UpdatePivotTableGroupItems(ExcelPivotTableField field, PivotTableCacheInternal cacheRef, bool addTypeDefault)
        {
            foreach (var pt in cacheRef._pivotTables)
            {
                var f = cacheRef.Fields[field.Index];
                if (f.Grouping is ExcelPivotTableFieldDateGroup)
                {
                    if (field.Index >= pt.Fields.Count)
                    {
                        pt.Fields.AddDateGroupField((int)f.Grouping.BaseIndex);
                    }

                    pt.Fields[field.Index].UpdateGroupItems(f, addTypeDefault);
                }
                else
                {
                    pt.Fields[field.Index].UpdateGroupItems(f, addTypeDefault);
                }
            }
        }