Пример #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
 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");
 }