Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/EPPlus/Drawing/Slicer/ExcelSlicerCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace OfficeOpenXml.Drawing.Slicer
/// </summary>
public abstract class ExcelSlicerCache : XmlHelper
{
const string _extPath = "x14:extLst/d:ext";
internal ExcelSlicerCache(XmlNamespaceManager nameSpaceManager) : base(nameSpaceManager)
{
}
Expand Down Expand Up @@ -108,5 +109,35 @@ internal void CreateWorkbookReference(ExcelWorkbook wb, string uriGuid)
var element = (XmlElement)xh.CreateNode("x14:slicerCache", false, true);
element.SetAttribute("id", ExcelPackage.schemaRelationships, CacheRel.Id);
}

const string _hideItemsWithNoDataPath = "x15:slicerCacheHideItemsWithNoData";
/// <summary>
/// If true, items that have no data are not displayed
/// </summary>
public bool HideItemsWithNoData
{
get
{
return ExistsNode(_extPath + "/" + _hideItemsWithNoDataPath);
}
set
{
if (value)
{
var node = CreateNode("x14:extLst/d:ext", false, true);
((XmlElement)node).SetAttribute("uri", ExtLstUris.SlicerCacheHideItemsWithNoDataUri);
var helper = XmlHelperFactory.Create(NameSpaceManager, node);
helper.CreateNode(_hideItemsWithNoDataPath, false, true);
}
else
{
var hideNode = GetNode(_extPath + "/" + _hideItemsWithNoDataPath);
if (hideNode != null)
{
hideNode.ParentNode.ParentNode.RemoveChild(hideNode.ParentNode);
}
}
}
}
}
}
29 changes: 0 additions & 29 deletions src/EPPlus/Drawing/Slicer/ExcelTableSlicerCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,6 @@ public bool CustomListSort
SetXmlNodeBool(_customListSortPath, value, true);
}
}
const string _hideItemsWithNoDataPath = "x15:slicerCacheHideItemsWithNoData";
/// <summary>
/// If true, items that have no data are not displayed
/// </summary>
public bool HideItemsWithNoData
{
get
{
return ExistsNode(_extPath +"/" + _hideItemsWithNoDataPath);
}
set
{
if(value)
{
var node = CreateNode("x14:extLst/d:ext",false,true);
((XmlElement)node).SetAttribute("uri", "{470722E0-AACD-4C17-9CDC-17EF765DBC7E}");
var helper = XmlHelperFactory.Create(NameSpaceManager, node);
helper.CreateNode(_hideItemsWithNoDataPath, false, true);
}
else
{
var hideNode = GetNode(_extPath + "/" + _hideItemsWithNoDataPath);
if(hideNode!=null)
{
hideNode.ParentNode.ParentNode.RemoveChild(hideNode.ParentNode);
}
}
}
}
const string _columnIndexPath = _topPath + "/@column";
internal int ColumnId
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace EPPlusTest.Table.PivotTable.Calculation
public class PivotTableCalculationSlicerTests : TestBase
{
static ExcelPackage _pck;
static ExcelTable _tbl1, _tbl2;
static ExcelTable _tbl1, _tbl2, _tbl3;
[ClassInitialize]
public static void Init(TestContext context)
{
Expand All @@ -27,6 +27,10 @@ public static void Init(TestContext context)
ws = _pck.Workbook.Worksheets.Add("Data2");
r = LoadItemData(ws);
_tbl2 = ws.Tables.Add(r, "Table2");
ws = _pck.Workbook.Worksheets.Add("Data3");
r = LoadItemData(ws);
ws.Cells["N10:N11"].Value = null;
_tbl3 = ws.Tables.Add(r, "Table3");
}
[ClassCleanup]
public static void Cleanup()
Expand Down Expand Up @@ -91,5 +95,25 @@ public void FilterSlicerMultipleItems()
Assert.AreEqual(ErrorValues.RefError, ws.Cells["F7"].Value);
Assert.AreEqual(358.8, ws.Cells["F8"].Value);
}
}

[TestMethod]
public void FilterSlicerMultipleItemsHideWithNoData()
{
var ws = _pck.Workbook.Worksheets.Add("PivotSlicerWithNoData");
var pt = ws.PivotTables.Add(ws.Cells["C3"], _tbl3, "PivotTableSlicerSingle");
pt.RowFields.Add(pt.Fields[0]);
var slicer = pt.Fields[0].AddSlicer();
slicer.SetPosition(1, 0, 8, 0);
pt.CacheDefinition.Refresh();
var df = pt.DataFields.Add(pt.Fields["Price"]);

Assert.AreEqual(slicer.Cache.Data.Items.Count, 6);

slicer.Cache.HideItemsWithNoData = true;
slicer.Cache.Data.Items.Refresh();

Assert.AreEqual(slicer.Cache.Data.Items[4].Hidden, false);
Assert.AreEqual(slicer.Cache.Data.Items[5].Hidden, false);
}
}
}
Loading