diff --git a/ClosedXML/Excel/PivotTables/IXLPivotTables.cs b/ClosedXML/Excel/PivotTables/IXLPivotTables.cs index 2838e87..45ca935 100644 --- a/ClosedXML/Excel/PivotTables/IXLPivotTables.cs +++ b/ClosedXML/Excel/PivotTables/IXLPivotTables.cs @@ -5,9 +5,15 @@ { public interface IXLPivotTables : IEnumerable { - IXLPivotTable AddNew(String name, IXLCell target, IXLRange source); + IXLPivotTable Add(String name, IXLCell targetCell, IXLRange range); - IXLPivotTable AddNew(String name, IXLCell target, IXLTable table); + IXLPivotTable Add(String name, IXLCell targetCell, IXLTable table); + + [Obsolete("Use Add instead")] + IXLPivotTable AddNew(String name, IXLCell targetCell, IXLRange range); + + [Obsolete("Use Add instead")] + IXLPivotTable AddNew(String name, IXLCell targetCell, IXLTable table); Boolean Contains(String name); diff --git a/ClosedXML/Excel/PivotTables/XLPivotTable.cs b/ClosedXML/Excel/PivotTables/XLPivotTable.cs index 5985ed4..6cbb361 100644 --- a/ClosedXML/Excel/PivotTables/XLPivotTable.cs +++ b/ClosedXML/Excel/PivotTables/XLPivotTable.cs @@ -61,7 +61,7 @@ if (!String.IsNullOrWhiteSpace(oldname) && !String.Equals(oldname, _name, StringComparison.OrdinalIgnoreCase)) { Worksheet.PivotTables.Delete(oldname); - Worksheet.PivotTables.Add(_name, this); + (Worksheet.PivotTables as XLPivotTables).Add(_name, this); } } } diff --git a/ClosedXML/Excel/PivotTables/XLPivotTables.cs b/ClosedXML/Excel/PivotTables/XLPivotTables.cs index 5d6a471..5df7957 100644 --- a/ClosedXML/Excel/PivotTables/XLPivotTables.cs +++ b/ClosedXML/Excel/PivotTables/XLPivotTables.cs @@ -13,30 +13,40 @@ this.Worksheet = worksheet ?? throw new ArgumentNullException(nameof(worksheet)); } - public void Add(String name, IXLPivotTable pivotTable) + internal void Add(String name, IXLPivotTable pivotTable) { _pivotTables.Add(name, (XLPivotTable)pivotTable); } - public IXLPivotTable AddNew(string name, IXLCell target, IXLRange source) + public IXLPivotTable Add(string name, IXLCell targetCell, IXLRange range) { var pivotTable = new XLPivotTable(this.Worksheet) { Name = name, - TargetCell = target, - SourceRange = source + TargetCell = targetCell, + SourceRange = range }; _pivotTables.Add(name, pivotTable); return pivotTable; } - public IXLPivotTable AddNew(string name, IXLCell target, IXLTable table) + public IXLPivotTable Add(string name, IXLCell targetCell, IXLTable table) { var dataRange = table.DataRange; var header = table.HeadersRow(); var range = table.Worksheet.Range(header.FirstCell(), dataRange.LastCell()); - return AddNew(name, target, range); + return Add(name, targetCell, range); + } + + public IXLPivotTable AddNew(string name, IXLCell targetCell, IXLRange range) + { + return Add(name, targetCell, range); + } + + public IXLPivotTable AddNew(string name, IXLCell targetCell, IXLTable table) + { + return Add(name, targetCell, table); } public Boolean Contains(String name) diff --git a/ClosedXML/Excel/Ranges/XLRangeBase.cs b/ClosedXML/Excel/Ranges/XLRangeBase.cs index 57524e8..3200de5 100644 --- a/ClosedXML/Excel/Ranges/XLRangeBase.cs +++ b/ClosedXML/Excel/Ranges/XLRangeBase.cs @@ -1667,7 +1667,7 @@ public XLPivotTable CreatePivotTable(IXLCell targetCell, String name) { - return (XLPivotTable)Worksheet.PivotTables.AddNew(name, targetCell, AsRange()); + return (XLPivotTable)Worksheet.PivotTables.Add(name, targetCell, AsRange()); } public IXLAutoFilter SetAutoFilter() diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index 701a799..c9c851d 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -479,7 +479,7 @@ if (target != null && source != null) { - var pt = ws.PivotTables.AddNew(pivotTableDefinition.Name, target, source) as XLPivotTable; + var pt = ws.PivotTables.Add(pivotTableDefinition.Name, target, source) as XLPivotTable; if (!String.IsNullOrWhiteSpace(StringValue.ToString(pivotTableDefinition?.ColumnHeaderCaption ?? String.Empty))) pt.SetColumnHeaderCaption(StringValue.ToString(pivotTableDefinition.ColumnHeaderCaption));