diff --git a/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java b/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java index 23dbc77f5..7a23a1396 100644 --- a/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java +++ b/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java @@ -383,8 +383,27 @@ public class CellSelection extends Selection { return false; } } - - ec.merge(row, row + rowSpan - 1, column, column + columnSpan - 1); + int rowStartIndex = row; + int rowEndIndex = row + rowSpan - 1; + int columnStartIndex = column; + int columnEndIndex = column + columnSpan - 1; + + // 合并已有单元格,还是新建单元格 + boolean hasCellElement = false; + for (int ri = rowStartIndex; ri <= rowEndIndex; ri++) { + for (int ci = columnStartIndex; ci <= columnEndIndex; ci++) { + CellElement ce = ec.getCellElement(ci, ri); + if (ce != null) { + hasCellElement = true; + break; + } + } + } + if (hasCellElement) { + ec.merge(row, row + rowSpan - 1, column, column + columnSpan - 1); + } else { + ec.addCellElement(DefaultThemedTemplateCellElementCase.createInstance(column, row, columnSpan, rowSpan, null), true); + } return true; }