ExcelSlicer

Namespace: EPPlus
We found 10 examples in language CSharp for this search. You will see 20 fragments of code.
		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerRangeItemNullXmlNodeThrowsException()
		{
			new SlicerRangeItem(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerRangeItemNullXmlNamespaceManagerThrowsException()
		{
			var xmlDoc = new XmlDocument(ExcelSlicer.SlicerDocumentNamespaceManager.NameTable);
			xmlDoc.LoadXml("<i n=\"[Bill-to Customer].[by Country by City].[Country].&amp;[AT]\" c=\"Austria\"/>");
			var node = xmlDoc.FirstChild;
			new SlicerRangeItem(node, null);
		}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void ConstructSlicerCacheTabularItemNullNodeThrowsException()
		{
			var slicerCacheNamespaceManager = ExcelSlicer.SlicerDocumentNamespaceManager;
			new SlicerCacheTabularItems(null, slicerCacheNamespaceManager);
		}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerSelectionNodeNullXmlNodeThrowsException()
		{
			new SlicerSelectionNode(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerSelectionNodeNullXmlNamespaceManagerThrowsException()
		{
			var xmlDoc = new XmlDocument(ExcelSlicer.SlicerDocumentNamespaceManager.NameTable);
			xmlDoc.LoadXml("<selection n=\"SlicerSelectionValue\" />");
			var node = xmlDoc.FirstChild;
			new SlicerSelectionNode(node, null);
		}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerRangeNodeNullXmlNodeThrowsException()
		{
			new SlicerRangeNode(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}
		#endregion

		#region Items Tests
		[TestMethod]
		public void SlicerRangeNodeItems()
		{
			var node = this.CreateSlicerRangeNode();
			var slicerRangeNode = new SlicerRangeNode(node, ExcelSlicer.SlicerDocumentNamespaceManager);
			Assert.AreEqual(3, slicerRangeNode.Items.Count);
			Assert.AreEqual(string.Empty, slicerRangeNode.Items[0].DisplayName);
			Assert.AreEqual("Austria", slicerRangeNode.Items[1].DisplayName);
			Assert.AreEqual("Belgium", slicerRangeNode.Items[2].DisplayName);
		}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TabularDataNodeNullXmlNodeThrowsException()
		{
			new TabularDataNode(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}
		#endregion

		#region Helper Methods
		private XmlNode CreateTabularDataNode()
		{
			var xmlDoc = new XmlDocument(ExcelSlicer.SlicerDocumentNamespaceManager.NameTable);
			xmlDoc.LoadXml(
			[email protected]"<tabular pivotCacheId=""1"" xmlns=""{ExcelPackage.schemaMain2009}"">
				<items count=""4"">
					<i x=""0""/>
					<i x=""1""/>
					<i x=""2"" s=""1""/>
					<i x=""3"" s=""1""/>
				</items>
			</tabular>");
			return xmlDoc.FirstChild;
		}

/*******************************************************************************
 * You may amend and distribute as you like, but don't remove this header!
 *
 * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
 * See http://www.codeplex.com/EPPlus for details.
 *
 * EPPlus Copyright (C) 2011 Jan Källman.
 * This File Copyright (C) 2016 Matt Delaney.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Lesser General Public License for more details.
 *
 * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
 * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
 *
 * All code and executables are provided "as is" with no warranty either express or implied. 
 * The author accepts no liability for any damage or loss of business that this product may cause.
 *
 * Code change notes:
 * 
 * Author                      Change                            Date
 * ******************************************************************************
 * Matt Delaney                Added support for slicers.        11 October 2016     
 *******************************************************************************/
using System.Linq;
using System.Xml;

namespace OfficeOpenXml.Drawing.Slicers
{
	/// <summary>
	/// Represents a single Excel Slicer in an <see cref="ExcelSlicers"/> file.
	/// </summary>
	public class ExcelSlicer : XmlHelper
	{
		#region Class Variables
		private static XmlNamespaceManager _slicerDocumentNamespaceManager;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the slicer cache associated with this slicer.
		/// </summary>
		public ExcelSlicerCache SlicerCache { get; private set; }

		/// <summary>
		/// Gets or sets this slicer's name attribute.
		/// </summary>
		public string Name
		{
			get { return base.GetXmlNodeString("@name"); }
			set { this.SetXmlNodeString("@name", value); }
		}

		/// <summary>
		/// Gets a namespace manager that contains the namespaces that are used by slicer.xml files.
		/// </summary>
		public static XmlNamespaceManager SlicerDocumentNamespaceManager
		{
			get
			{
				if (ExcelSlicer._slicerDocumentNamespaceManager == null)
				{
					var nameTable = new NameTable();
					var namespaceManager = new XmlNamespaceManager(nameTable);
					namespaceManager.AddNamespace(string.Empty, ExcelPackage.schemaMain2009);
					// Hack to work around a bug where SelectSingleNode ignores the default namespace.
					namespaceManager.AddNamespace("default", ExcelPackage.schemaMain2009);
					namespaceManager.AddNamespace("x", ExcelPackage.schemaMain);
					namespaceManager.AddNamespace("mc", ExcelPackage.schemaMarkupCompatibility);
					namespaceManager.AddNamespace("x15", ExcelPackage.schemaMain2010);
					_slicerDocumentNamespaceManager = namespaceManager;
				}
				return ExcelSlicer._slicerDocumentNamespaceManager;
			}
		}

		private ExcelWorksheet Worksheet { get; set; }
		#endregion

		#region Constructors
		/// <summary>
		/// Initialize a new <see cref="ExcelSlicer"/> based on the specified <paramref name="node"/>.
		/// </summary>
		/// <param name="node">The "<slicer/>" node that this slicer represents.</param>
		/// <param name="namespaceManager">The namespace manager to use to process the slicer.</param>
		/// <param name="worksheet">The <see cref="ExcelWorksheet"/> that the slicer's drawing exists on.</param>
		internal ExcelSlicer(XmlNode node, XmlNamespaceManager namespaceManager, ExcelWorksheet worksheet) : base(namespaceManager, node)
		{
			this.Worksheet = worksheet;
			var cacheName = node.Attributes["cache"].Value;
			this.SlicerCache = this.Worksheet.Workbook.SlicerCaches.Last(cache => cache.Name == cacheName);
			this.SlicerCache.Slicer = this;
		}
		#endregion
	}
}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void OlapDataNodeNullXmlNodeThrowsException()
		{
			new OlapDataNode(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}
		#endregion

		#region Selections Tests
		[TestMethod]
		public void OlapDataNodeSelections()
		{
			var node = this.CreateOlapDataNode();
			var olapDataNode = new OlapDataNode(node, ExcelSlicer.SlicerDocumentNamespaceManager);
			Assert.AreEqual(1, olapDataNode.Selections.Count);
			Assert.AreEqual("[Bill-to Customer].[by Country by City].[All Customer]", olapDataNode.Selections[0].Name);
		}

		#region Constructor Tests
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SlicerLevelNodeNullXmlNodeThrowsException()
		{
			new SlicerLevelNode(null, ExcelSlicer.SlicerDocumentNamespaceManager);
		}

/*************************************************************************************************
  Required Notice: Copyright (C) EPPlus Software AB. 
  This software is licensed under PolyForm Noncommercial License 1.0.0 
  and may only be used for noncommercial purposes 
  https://polyformproject.org/licenses/noncommercial/1.0.0/

  A commercial license to use this software can be purchased at https://epplussoftware.com
 *************************************************************************************************
  Date               Author                       Change
 *************************************************************************************************
  04/15/2020         EPPlus Software AB       EPPlus 5.2
 *************************************************************************************************/
using OfficeOpenXml.Drawing.Slicer;

namespace OfficeOpenXml
{
    /// <summary>
    /// Buildin slicer styles
    /// </summary>
    public enum eSlicerStyle
    {
        /// <summary>
        /// No slicer style specified
        /// </summary>
        None,
        /// <summary>
        /// A custom style set by the <see cref="ExcelSlicer{T}.Style"/> property
        /// </summary>
        Custom,
        /// <summary>
        /// Light 1 style
        /// </summary>
        Light1,
        /// <summary>
        /// Light 2 style
        /// </summary>
        Light2,
        /// <summary>
        /// Light 3 style
        /// </summary>
        Light3,
        /// <summary>
        /// Light 4 style
        /// </summary>
        Light4,
        /// <summary>
        /// Light 5 style
        /// </summary>
        Light5,
        /// <summary>
        /// Light 6 style
        /// </summary>
        Light6,
        /// <summary>
        /// Other 1 style
        /// </summary>
        Other1,
        /// <summary>
        /// Other 2 style
        /// </summary>
        Other2,
        /// <summary>
        /// Dark 1 style
        /// </summary>
        Dark1,
        /// <summary>
        /// Dark 2 style
        /// </summary>
        Dark2,
        /// <summary>
        /// Dark 3 style
        /// </summary>
        Dark3,
        /// <summary>
        /// Dark 4 style
        /// </summary>
        Dark4,
        /// <summary>
        /// Dark 5 style
        /// </summary>
        Dark5,
        /// <summary>
        /// Dark 6 style
        /// </summary>
        Dark6
    }
}

		#endregion

		#region Internal Methods
		/// <summary>
		/// Refreshes the slicer cache's values.
		/// </summary>
		internal void Refresh(ExcelPivotCacheDefinition cacheDefinition, List<CacheItem> previouslySelectedItems)
		{
			// If all are selected and a new value is added, it is selected.
			// Otherwise new values are added as deselected.
			bool isFiltered = this.TabularDataNode.Items.Any(i => !i.IsSelected);
			var cacheFieldIndex = cacheDefinition.GetCacheFieldIndex(this.SourceName);
			var cacheField = cacheDefinition.CacheFields[cacheFieldIndex];
			var cacheItems = cacheDefinition.GetCacheItemsForSlicer(cacheField);

			this.TabularDataNode.Items.Clear();

			if (isFiltered)
			{
				for (int i = 0; i < cacheItems.Count; i++)
				{
					var sharedItem = cacheItems[i];
					bool isSelected = previouslySelectedItems.Any(si => si.Value == sharedItem.Value && si.Type == sharedItem.Type);
					this.TabularDataNode.Items.Add(i, isSelected);
				}
			}
			else
				cacheItems.ForEach((c, i) => this.TabularDataNode.Items.Add(i, true));
		}

		/// <summary>
		/// Applies the sort and hide settings to the slice values. This must be called after
		/// pivot tables are refreshed in order to work properly.
		/// </summary>
		/// <param name="cacheDefinition">The backing cache definition.</param>
		internal void ApplySettings(ExcelPivotCacheDefinition cacheDefinition)
		{
			var cacheFieldIndex = cacheDefinition.GetCacheFieldIndex(this.SourceName);
			var cacheField = cacheDefinition.CacheFields[cacheFieldIndex];
			var cacheItems = cacheDefinition.GetCacheItemsForSlicer(cacheField);
			var sortedItems = this.Sort(cacheField, cacheItems);
			sortedItems = this.ApplyNoDataSettings(sortedItems, cacheDefinition, cacheFieldIndex, cacheField, cacheItems);
			this.TabularDataNode.Items.Clear();
			this.TabularDataNode.Items.AddRange(sortedItems);
		}

		/// <summary>
		/// Save this <see cref="ExcelSlicerCache"/> back into the <paramref name="package"/> at.
		/// </summary>
		/// <param name="package">The <see cref="ExcelPackage"/> to save to.</param>
		internal void Save(ExcelPackage package)
		{
			package.SavePart(new Uri("/xl/" + this.SlicerCacheUri, UriKind.Relative), this.Part);
		}
		#endregion

		#region Private Methods
		private List<TabularItemNode> Sort(CacheFieldNode cacheField, SharedItemsCollection cacheItems)
		{
			// Sort the fields according to their types.
			IComparer<string> comparer = null;
			if (this.TabularDataNode.CustomListSort && cacheField.IsDateGrouping)
			{
				if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Months)
					comparer = new MonthComparer();
				else if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Days)
					comparer = new DayComparer();
			}
			else
				comparer = new NaturalComparer();

			// Sort the slicer cache items.
			if (this.TabularDataNode.SortOrder == SortOrder.Descending)
				return this.TabularDataNode.Items.OrderByDescending(t => cacheItems[t.AtomIndex].Value, comparer).ToList();
			return this.TabularDataNode.Items.OrderBy(t => cacheItems[t.AtomIndex].Value, comparer).ToList();
		}
		
		private List<TabularItemNode> ApplyNoDataSettings(List<TabularItemNode> sortedItems, ExcelPivotCacheDefinition cacheDefinition, 
			int cacheFieldIndex, CacheFieldNode cacheField, SharedItemsCollection cacheItems)
		{
			var pivotTables = this.GetRelatedPivotTables(cacheDefinition);
			if (this.HideItemsWithNoData)
			{
				foreach (var item in sortedItems)
				{
					// TODO: Task #13685 - Implement hide items with no data settings.
					if (!this.PivotTablesContainItem(item, pivotTables, cacheFieldIndex, cacheItems))
						item.NoData = true;
				}
			}
			else
			{
				if (this.TabularDataNode.CrossFilter == CrossFilter.Both)
				{
					var usedItems = new List<TabularItemNode>();
					var unusedItems = new List<TabularItemNode>();
					foreach (var item in sortedItems)
					{
						bool hasData = this.PivotTablesContainItem(item, pivotTables, cacheFieldIndex, cacheItems);
						if (hasData)
							usedItems.Add(item);
						else
							unusedItems.Add(item);
					}
					sortedItems = usedItems.Concat(unusedItems).ToList();
				}

				if (!this.TabularDataNode.ShowMissing)
				{
					foreach (var item in sortedItems)
					{
						if (cacheItems[item.AtomIndex].Unused)
							item.NoData = true;
					}
				}
			}
			return sortedItems;
		}

		private bool PivotTablesContainItem(TabularItemNode item, List<ExcelPivotTable> pivotTables, 
			int cacheFieldIndex, SharedItemsCollection cacheItems)
		{
			// Cache field items marked as unused are never referenced in a pivot table.
			if (cacheItems[item.AtomIndex].Unused)
				return false;

			foreach (var pivotTable in pivotTables)
			{
				if (pivotTable.ContainsData(cacheFieldIndex, item.AtomIndex))
					return true;
			}
			return false;
		}

OfficeOpenXml.Drawing.Slicer.ExcelSlicer<T> : IDisposable, IPictureContainer

Methods :

public eDrawingType get_DrawingType()
public String get_Caption()
public Void set_Caption(String value = )
public Boolean get_ShowCaption()
public Void set_ShowCaption(Boolean value = )
public String get_SlicerName()
public Void set_SlicerName(String value = )
public Double get_RowHeight()
public Void set_RowHeight(Double value = )
public Int32 get_StartItem()
public Void set_StartItem(Int32 value = )
public Int32 get_ColumnCount()
public Void set_ColumnCount(Int32 value = )
public Boolean get_LockedPosition()
public Void set_LockedPosition(Boolean value = )
public eSlicerStyle get_Style()
public Void set_Style(eSlicerStyle value = )
public String get_StyleName()
public Void set_StyleName(String value = )
public T get_Cache()
public String get_Name()
public Void set_Name(String value = )
public String get_Description()
public Void set_Description(String value = )
public eEditAs get_EditAs()
public Void set_EditAs(eEditAs value = )
public Boolean get_Locked()
public Void set_Locked(Boolean value = )
public Boolean get_Print()
public Void set_Print(Boolean value = )
public ExcelPosition get_From()
public ExcelDrawingCoordinate get_Position()
public ExcelDrawingSize get_Size()
public ExcelPosition get_To()
public Uri get_Hyperlink()
public Void set_Hyperlink(Uri value = )
public ExcelDrawingAsType get_As()
public Void SetPosition(Int32 PixelTop = , Int32 PixelLeft = )
public eEditAs get_CellAnchor()
public Void ChangeCellAnchor(eEditAs type = , Int32 PixelTop = , Int32 PixelLeft = , Int32 width = , Int32 height = )
public Void ChangeCellAnchor(eEditAs type = )
public Void SetPosition(Int32 Row = , Int32 RowOffsetPixels = , Int32 Column = , Int32 ColumnOffsetPixels = )
public Void SetSize(Int32 Percent = )
public Void SetSize(Int32 PixelWidth = , Int32 PixelHeight = )
public Void SendToBack()
public Void BringToFront()
public ExcelGroupShape Group(ExcelDrawing[] drawing = )
public Void UnGroup(Boolean ungroupThisItemOnly = True)
public ExcelGroupShape get_ParentGroup()
public Void Dispose()
public Void AdjustPositionAndSize()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods