Skip to content

Commit 5cebefe

Browse files
committed
Fixes issue #2228
1 parent 057d3ab commit 5cebefe

2 files changed

Lines changed: 58 additions & 5 deletions

File tree

src/EPPlus/Core/ChangableDictionary.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,21 @@ internal virtual void InsertAndShift(int fromPosition, int add)
6161
{
6262
var pos = Array.BinarySearch(_index[0], 0, _count, fromPosition);
6363

64-
if (pos + 1 >= _index[0].Length - 1)
64+
if (pos < 0)
6565
{
66-
Array.Resize(ref _index[0], _index[0].Length << 1);
67-
Array.Resize(ref _index[1], _index[1].Length << 1);
66+
pos = ~pos;
6867
}
6968

70-
if (pos<0)
69+
if (pos + 1 >= _index[0].Length - 1)
7170
{
72-
pos = ~pos;
71+
Array.Resize(ref _index[0], _index[0].Length << 1);
72+
Array.Resize(ref _index[1], _index[1].Length << 1);
7373
}
7474

7575
Array.Copy(_index[0], pos, _index[0], pos + 1, _count - pos);
7676
Array.Copy(_index[1], pos, _index[1], pos + 1, _count - pos);
7777

78+
7879
_count++;
7980
for (int i=pos;i<Count;i++)
8081
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* You may amend and distribute as you like, but don't remove this header!
3+
*
4+
* Required Notice: Copyright (C) EPPlus Software AB.
5+
* https://epplussoftware.com
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
18+
* If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
19+
*
20+
* All code and executables are provided "" as is "" with no warranty either express or implied.
21+
* The author accepts no liability for any damage or loss of business that this product may cause.
22+
*
23+
* Code change notes:
24+
*
25+
Date Author Change
26+
*******************************************************************************
27+
01/27/2020 EPPlus Software AB Initial release EPPlus 5
28+
*******************************************************************************/using Microsoft.VisualStudio.TestTools.UnitTesting;
29+
using OfficeOpenXml;
30+
using System;
31+
using System.Collections.Generic;
32+
using System.Linq;
33+
using System.Text;
34+
using System.Threading.Tasks;
35+
36+
namespace EPPlusTest.Issues
37+
{
38+
[TestClass]
39+
public class CellStoreIssues
40+
{
41+
[TestMethod]
42+
public void Issue2228()
43+
{
44+
using var pck = new ExcelPackage();
45+
var worksheet = pck.Workbook.Worksheets.Add("Sheet1");
46+
for (int i = 1; i < 10; i++)
47+
{
48+
worksheet.InsertColumn(i, 1);
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)