Skip to content
Closed
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
13 changes: 4 additions & 9 deletions main/SS/UserModel/Helpers/RowShifter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ public List<CellRangeAddress> ShiftMergedRegions(int startRow, int endRow, int n
var merged = sheet.GetMergedRegion(i);

// remove merged region that overlaps Shifting
var lastCol = sheet.GetRow(startRow) != null
? sheet.GetRow(startRow).LastCellNum
: sheet.GetRow(endRow) != null
? sheet.GetRow(endRow).LastCellNum
: 0;
if (RemovalNeeded(merged, startRow, endRow, n, lastCol))
if (RemovalNeeded(merged, startRow, endRow, n))
{
removedIndices.Add(i);
continue;
Expand Down Expand Up @@ -103,7 +98,7 @@ public List<CellRangeAddress> ShiftMergedRegions(int startRow, int endRow, int n
}

// Keep in sync with {@link ColumnShifter#removalNeeded}
private bool RemovalNeeded(CellRangeAddress merged, int startRow, int endRow, int n, int lastCol)
private bool RemovalNeeded(CellRangeAddress merged, int startRow, int endRow, int n)
{
var movedRows = endRow - startRow + 1;

Expand All @@ -115,14 +110,14 @@ private bool RemovalNeeded(CellRangeAddress merged, int startRow, int endRow, in
// area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
var firstRow = Math.Max(endRow + 1, endRow + n - movedRows);
var lastRow = endRow + n;
overwrite = new CellRangeAddress(firstRow, lastRow, 0, lastCol);
overwrite = new CellRangeAddress(firstRow, lastRow, merged.FirstColumn, merged.LastColumn);
}
else
{
// area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
var firstRow = startRow + n;
var lastRow = Math.Min(startRow - 1, startRow + n + movedRows);
overwrite = new CellRangeAddress(firstRow, lastRow, 0, lastCol);
overwrite = new CellRangeAddress(firstRow, lastRow, merged.FirstColumn, merged.LastColumn);
}

// if the merged-region and the overwritten area intersect, we need to remove it
Expand Down