Skip to content

Commit

Permalink
Update RowShifter.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLee88 committed Oct 30, 2024
1 parent 0a0d59f commit 5bb489a
Showing 1 changed file with 4 additions and 9 deletions.
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

0 comments on commit 5bb489a

Please sign in to comment.