# Merge Cells

DsExcel allows you to execute the merge operation on several cells by combining them into a single cell.

## Content

DsExcel Java enables users to execute the merge operation on several cells by combining them into a single cell using [merge](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IRange.html#merge) method of the [IRange](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IRange.html) interface. When a cell range is merged, the data of top left cell stays in the final merged cell, and the data of other cells in the given range is lost.
If all the cells within the given range are empty, the formatting of top left cell in the cell range is applied to the merged cell, by default.
In order to merge the range of cells, refer to the following example code.

```Java
// Merge the cell range A1:B4 into one single cell
worksheet.getRange("A1:B4").merge();
```

![](https://cdn.mescius.io/document-site-files/images/dd59ea42-cd61-4fa6-a018-6231c2a9c598/images/merge-cells.png)

In order to merge only the rows of the specified range of cell into one, refer to the following example code.

```Java
// Merge the cell range C1:D4 into a single merged cell in one row.
worksheet.getRange("C1:D4").merge(true);
```

![](https://cdn.mescius.io/document-site-files/images/dd59ea42-cd61-4fa6-a018-6231c2a9c598/images/merge-cells-one-row.png)

## See Also

[Get Range and Range Area](/document-solutions/java-excel-api/docs/online/Features/ManageWorksheet/RangeOperations/GetRangeAndRangeArea)
[Insert and Delete Rows and Columns](/document-solutions/java-excel-api/docs/online/Features/ManageWorksheet/RangeOperations/InsertAndDeleteRowsAndColumns)
[Work with Used Range](/document-solutions/java-excel-api/docs/online/Features/ManageWorksheet/RangeOperations/WorkWithUsedRange)