Merging and Unmerging Cells

Merging Cells in a Worksheet.

Using Microsoft Excel

The following steps describe how to merge cells in the worksheet using Microsoft Excel.

  1. Copy the data you want into the upper-leftmost cell within the range.
  2. Select the cells you want to merge.
  3. To merge cells in a row or column and center the cell contents, click Merge and Center icon on the Formatting toolbar.

Using Aspose.Cells

The Cells class has some useful methods for the task. For example, the method merge() merges the cells into a single cell within a specified range of the cells.

The following output is generated after executing the code below.

The cells (C6:E7) have been merged

todo:image_alt_text

Code Example

The following example shows how to merge cells (C6:E7) in a worksheet.

Unmerging (Splitting) Merged Cells

Using Microsoft Excel

The following steps describe how to split merged cells using Microsoft Excel.

  1. Select the merged cell. When cells have been combined, Merge and Center is selected on the Formatting toolbar.
  2. Click Merge and Center on the Formatting toolbar.

Using Aspose.Cells

The Cells class has a method named unMerge() that splits cells into their original state. The method unmerges the cells using the cell’s reference in the merged cell range.

Code Example

The following example shows how to split the merged cells (C6). The example uses the file created in the previous example and splits the merged cells.