Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Fixed issue #345
Browse files Browse the repository at this point in the history
  • Loading branch information
EPPlus committed Dec 31, 2018
1 parent 2559308 commit 30cdb0d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion EPPlus/CellStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ private int DeletePage(int fromRow, int rows, ColumnIndex column, int pagePos, b
var delSize=page.MaxIndex - page.MinIndex+1;
rows -= delSize;
var prevOffset = page.Offset;
Array.Copy(column._pages, pagePos + 1, column._pages, pagePos, column.PageCount - pagePos + 1);
Array.Copy(column._pages, pagePos + 1, column._pages, pagePos, column.PageCount - pagePos);
column.PageCount--;
if (column.PageCount == 0)
{
Expand Down
23 changes: 11 additions & 12 deletions EPPlus/ExcelRangeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,6 @@ public void Sort(int[] columns, bool[] descending = null, CultureInfo culture =
var formulas = GetItems(_worksheet._formulas, _fromRow, _fromCol, _toRow, _toCol);
var hyperLinks = GetItems(_worksheet._hyperLinks, _fromRow, _fromCol, _toRow, _toCol);
var comments = GetItems(_worksheet._commentsStore, _fromRow, _fromCol, _toRow, _toCol);
var sf = new HashSet<int>();
//Sort the values and styles.
_worksheet._values.Clear(_fromRow, _fromCol, _toRow - _fromRow + 1, cols);
for (var r = 0; r < l.Count; r++)
Expand All @@ -3009,19 +3008,19 @@ public void Sort(int[] columns, bool[] descending = null, CultureInfo culture =
_worksheet._formulas.SetValue(row, col, formulas[addr]);
if (formulas[addr] is int)
{
var sfIx = (int)formulas[addr];
if (!sf.Contains(sfIx))
int sfIx = (int)formulas[addr];
var startAddr = new ExcelAddress(Worksheet._sharedFormulas[sfIx].Address);
var f = Worksheet._sharedFormulas[sfIx];
if (startAddr._fromRow > row)
{
var startAddr = new ExcelAddress(Worksheet._sharedFormulas[sfIx].Address);
if (startAddr._fromRow > row)
{
var f = Worksheet._sharedFormulas[sfIx];
f.Formula = ExcelCellBase.TranslateFromR1C1(ExcelCellBase.TranslateToR1C1(f.Formula, f.StartRow, f.StartCol), row, f.StartCol);
f.StartRow = row;
f.Address = ExcelCellBase.GetAddress(row, col, startAddr._toRow, startAddr._toCol);
}
f.Formula = ExcelCellBase.TranslateFromR1C1(ExcelCellBase.TranslateToR1C1(f.Formula, f.StartRow, f.StartCol), row, f.StartCol);
f.StartRow = row;
f.Address = ExcelCellBase.GetAddress(row, startAddr._fromCol, startAddr._toRow, startAddr._toCol);
}
else if (startAddr._toRow < row)
{
f.Address = ExcelCellBase.GetAddress(startAddr._fromRow, startAddr._fromCol, row, startAddr._toCol);
}
sf.Add(sfIx);
}
}

Expand Down
14 changes: 13 additions & 1 deletion EPPlusTest/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ public void Issue376()
[TestMethod]
public void Issue367()
{
using(var pck = new ExcelPackage(new FileInfo(@"c:\Temp\ProductFunctionTest.xlsx")))
using(var pck = OpenTemplatePackage(@"ProductFunctionTest.xlsx"))
{
var sheet = pck.Workbook.Worksheets.First();
//sheet.Cells["B13"].Value = null;
Expand All @@ -2359,5 +2359,17 @@ public void Issue367()
Assert.AreEqual(0d, sheet.Cells["B16"].Value);
}
}
[TestMethod]
public void Issue345()
{
using (ExcelPackage package = OpenTemplatePackage("issue345.xlsx"))
{
var worksheet = package.Workbook.Worksheets["test"];
int[] sortColumns = new int[1];
sortColumns[0] = 0;
worksheet.Cells["A2:A30864"].Sort(sortColumns);
package.Save();
}
}
}
}

0 comments on commit 30cdb0d

Please sign in to comment.