diff --git a/src/EPPlus/Core/ChangableDictionary.cs b/src/EPPlus/Core/ChangableDictionary.cs index 260f7a4849..cd8d3af904 100644 --- a/src/EPPlus/Core/ChangableDictionary.cs +++ b/src/EPPlus/Core/ChangableDictionary.cs @@ -59,6 +59,7 @@ internal T this[int key] internal virtual void InsertAndShift(int fromPosition, int add) { + if (_count == 0) return; var pos = Array.BinarySearch(_index[0], 0, _count, fromPosition); if (pos < 0) @@ -66,7 +67,7 @@ internal virtual void InsertAndShift(int fromPosition, int add) pos = ~pos; } - if (_count >= _index[0].Length - 1) + if (_count >= _index[0].Length-1) { Array.Resize(ref _index[0], _index[0].Length << 1); Array.Resize(ref _index[1], _index[1].Length << 1); @@ -83,6 +84,23 @@ internal virtual void InsertAndShift(int fromPosition, int add) } Version++; } + internal virtual void Shift(int fromPosition, int add) + { + if (_count == 0) return; + var pos = Array.BinarySearch(_index[0], 0, _count, fromPosition); + + if (pos < 0) + { + pos = ~pos; + } + if (pos >= _count) return; + + for (int i = pos; i < Count; i++) + { + _index[0][i] += add; + } + Version++; + } internal int Count { get { return _count; } } /// diff --git a/src/EPPlus/Core/Worksheet/WorksheetRangeInsertHelper.cs b/src/EPPlus/Core/Worksheet/WorksheetRangeInsertHelper.cs index 0c76bc119d..ae542a4753 100644 --- a/src/EPPlus/Core/Worksheet/WorksheetRangeInsertHelper.cs +++ b/src/EPPlus/Core/Worksheet/WorksheetRangeInsertHelper.cs @@ -706,6 +706,9 @@ private static void AdjustColumns(ExcelWorksheet ws, int columnFrom, int columns } } + //Shift column indexes from columnFrom + ws.ColumnLookup.Shift(columnFrom, columns); + for (int i = lst.Count - 1; i >= 0; i--) { var c = lst[i]; diff --git a/src/EPPlus/Drawing/ExcelDrawing.cs b/src/EPPlus/Drawing/ExcelDrawing.cs index 08fe0167ff..f8843ed967 100644 --- a/src/EPPlus/Drawing/ExcelDrawing.cs +++ b/src/EPPlus/Drawing/ExcelDrawing.cs @@ -15,6 +15,7 @@ Date Author Change using OfficeOpenXml.Drawing.Controls; using OfficeOpenXml.Drawing.OleObject; using OfficeOpenXml.Drawing.Slicer; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using OfficeOpenXml.Packaging; using OfficeOpenXml.Utils.Drawings; using OfficeOpenXml.Utils.EnumUtils; @@ -344,18 +345,7 @@ public virtual string Name // All uniqueness checks successfully passed! Safe to update name-lookup dictionaries. UpdateNameInDictionaries(oldName, value); } - - SetXmlNodeString(_nvPrPath + "/@name", value); - if (this is ExcelSlicer ts) - { - SetXmlNodeString(_nvPrPath + "/../../a:graphic/a:graphicData/sle:slicer/@name", value); - ts.SlicerName = value; - } - else if (this is ExcelSlicer pts) - { - SetXmlNodeString(_nvPrPath + "/../../a:graphic/a:graphicData/sle:slicer/@name", value); - pts.SlicerName = value; - } + SetName(value); } catch (ArgumentException) { @@ -367,6 +357,20 @@ public virtual string Name } } } + internal void SetName(string name) + { + SetXmlNodeString(_nvPrPath + "/@name", name); + if (this is ExcelSlicer ts) + { + SetXmlNodeString(_nvPrPath + "/../../a:graphic/a:graphicData/sle:slicer/@name", name); + ts.SlicerName = name; + } + else if (this is ExcelSlicer pts) + { + SetXmlNodeString(_nvPrPath + "/../../a:graphic/a:graphicData/sle:slicer/@name", name); + pts.SlicerName = name; + } + } /// @@ -1719,6 +1723,10 @@ public void UnGroup(bool ungroupThisItemOnly = true) } else { + foreach (var item in _parent.Drawings) + { + _drawings.AddDrawingInternal(item); + } _parent.Drawings.Clear(); } if (prevParent.Drawings.Count <= 0) @@ -2485,7 +2493,7 @@ private XmlNode CopyShape(ExcelChartStandard targetChart, bool isGroupShape = fa drawNode.InnerXml = TopNode.InnerXml; var targetShape = GetDrawing(targetChart.Drawings._drawings, drawNode, DrawingsCollectionType.Chart) as ExcelShape; targetShape.Id = ++targetChart.Drawings._nextDrawingId; - targetShape.Name = targetChart.Drawings.GetUniqueDrawingName(this.Name); + targetShape.SetName(targetChart.Drawings.GetUniqueDrawingName(this.Name)); } return drawNode; } diff --git a/src/EPPlus/Drawing/ExcelDrawings.cs b/src/EPPlus/Drawing/ExcelDrawings.cs index 3f200ec907..7cd6b77992 100644 --- a/src/EPPlus/Drawing/ExcelDrawings.cs +++ b/src/EPPlus/Drawing/ExcelDrawings.cs @@ -208,6 +208,7 @@ internal string GetUniqueDrawingName(string name) { var newName = name; var index = 1; + while (_drawingNames.ContainsKey(newName)) { var split = newName.Split(' '); diff --git a/src/EPPlus/Drawing/ExcelShape.cs b/src/EPPlus/Drawing/ExcelShape.cs index 0d0fe50131..46a17183f4 100644 --- a/src/EPPlus/Drawing/ExcelShape.cs +++ b/src/EPPlus/Drawing/ExcelShape.cs @@ -10,6 +10,7 @@ Date Author Change ************************************************************************************************* 01/27/2020 EPPlus Software AB Initial release EPPlus 5 *************************************************************************************************/ +using System; using System.Text; using System.Xml; using OfficeOpenXml.Drawing.Interfaces; @@ -89,5 +90,6 @@ internal override void DeleteMe() } base.DeleteMe(); } + } } diff --git a/src/EPPlus/ExcelWorksheet.cs b/src/EPPlus/ExcelWorksheet.cs index dd507d8bd9..38375c721f 100644 --- a/src/EPPlus/ExcelWorksheet.cs +++ b/src/EPPlus/ExcelWorksheet.cs @@ -2275,7 +2275,7 @@ public void InsertColumn(int columnFrom, int columns) public void InsertColumn(int columnFrom, int columns, int copyStylesFromColumn) { WorksheetRangeInsertHelper.InsertColumn(this, columnFrom, columns, copyStylesFromColumn); - ColumnLookup.InsertAndShift(columnFrom, columns); + //ColumnLookup.InsertAndShift(columnFrom, columns); } #endregion #region DeleteRow