Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,37 @@ Cell GetMinMergedCell(int row)
return cell;
}
}

// Fallback: all cells in this row begin multi-row spans (MergeDown > 0),
// so no cell satisfies `resultRowIndex + MergeDown == row`.
// This occurs when a single cell spans all columns and more than one row
// (e.g. MergeRight = columnCount - 1, MergeDown >= 1).
// Find the cell with the minimum MergeDown instead —
// this matches the behaviour of GetMinMergedCellOriginal.
int minMergeDown = int.MaxValue;
Cell? minCell = null;
for (int idx = 0; idx < clsCount; idx++)
{
var cell = resultRow[idx];
if (!_mergedCells.Contains(cell))
continue;
if (cell.MergeDown < minMergeDown)
{
minMergeDown = cell.MergeDown;
minCell = cell;
if (minMergeDown == 0)
break; // Can't get better.
}
}
if (minCell is not null)
{
#if DEBUG
Debug.Assert(originalResult.Row!.Index + originalResult.MergeDown ==
minCell.Row!.Index + minCell.MergeDown);
#endif
return minCell;
}

throw new InvalidOperationException("GetMinMergedCell: Unexpected problem #1");
}

Expand Down