Phpspreadsheet merge cells by column and row

# Merging cells

To merge a range of cells, use ->mergeCells($range).

$sheet->mergeCells('A1:E1');

# Merging columns and rows

To merge columns and rows, use ->setMergeColumn($array).

$sheet->setMergeColumn(array(
    'columns' => array('A','B','C','D'),
    'rows' => array(
        array(2,3),
        array(5,11),
    )
));

For a Microsoft Excel 98 version and a Microsoft Excel 2001 for Mac version of this article, see 179045.

Symptoms

You may be unable to use the AutoFit feature for columns or rows that contain merged cells in Microsoft Excel. In addition, if the Wrap Text feature is also selected, text is not wrapped automatically.

Cause

In Excel, you cannot use the AutoFit feature on a column that contains a cell merged with cells in other columns. Likewise, you cannot use AutoFit on a row that contains a cell merged with cells in other rows.

Workaround

When you use merged cells, manually adjust row height and column width by using the following procedures, as appropriate for the version of Excel that you are running.

Microsoft Office Excel 2003 and earlier versions of Excel

  • On the Format menu, point to Row, and then click Height.

  • On the Format menu, point to Column, and then click Width.

Microsoft Office Excel 2007

  • On the Home tab, click
    Format in the Cells group, and then click
    Row Height.

  • On the Home tab, click
    Format in the Cells group, and then click
    Column Width.

Need more help?

Merge Cells is an add-in for Microsoft Excel that combines multiple text cells. Use it to join values from several cells to one and merge several cells, rows, or columns keeping all data.

  • Before you start
  • Merging options
  • Start Merge Cells
  • How to combine Excel cells, columns, and rows
  • Combine cells with aggregate Excel functions
  • Related links

Before you start

  • A special Back up this worksheet option will create a safe copy of your original sheet.
  • The add-in brings together all areas in the selection, including non-adjacent ones.

Merging options

After you select the range, you'll have to pick one of the merging options for the cells. Please see below the examples of how each of them works.

Start Merge Cells

Run the add-in by clicking on its icon in the Merge group on the Ablebits Data tab:

Phpspreadsheet merge cells by column and row

How to combine Excel cells, columns, and rows

The add-in's window lets you adjust the following options:

Phpspreadsheet merge cells by column and row

  1. Select the range in your worksheet or use the Expand selection or Select range icons on the right.
  2. In this dropdown, choose the merging option: Columns into one, Rows into one, Cells into one.
  3. Combine with offers a set of standard delimiters to use between the merged values: semicolon, comma, period, space, line break. Also, you can scroll down to select an aggregate function, please see more details in the Combine cells with aggregate Excel functions section.

    Tip. You can enter any combination of characters into the field or leave it blank to stitch the values together. The separators you enter manually are saved in the drop-down list for the next time you use the add-in.

  4. Choose destination for the result in the Place the results to drop-down list: left or right column; top or bottom row; top-left, top-right, bottom-left, or bottom-right cell.
  5. Use the additional options to adapt the results to your table:
    • Check the Clear the contents of the selected cells checkbox to delete the source values after merging them.
    • If you want to combine the selected cells, and not only their values, choose to Merge all areas in the selection.
    • Avoid getting extra separators when merging values by checking off Skip empty cells.
    • Select the Wrap text option to make the joined values visible in your worksheet.
  6. We recommend selecting Back up this worksheet to get a copy of your current table as is.

Click the Merge button to combine values from the selected columns in Excel.

Combine cells with aggregate Excel functions

If you've got numerical data, you can not only combine values but also apply aggregate Excel functions. For this, select the function of interest in the Combine with drop-down list:

Phpspreadsheet merge cells by column and row

Note. For the calculations, the tool uses the standard Excel functions (AVERAGE, COUNT, COUNTA, MAX, MIN, SUM), so if you face certain difficulties, please consult a corresponding section here.

  • How to merge two tables in Excel
  • How to merge duplicates in Excel
  • How to consolidate several files in Excel
  • How to combine worksheets by columns

Can you merge rows and columns at the same time?

You can also merge multiple columns of different rows into a single row by using the CONCATENATE formula. After typing the formula you need to select the cells of a row then put a comma and select cells from another row and so on.

How do I merge cells columns and rows?

How to merge cells.
Highlight the cells you want to merge..
Click on the arrow just next to "Merge and Center.".
Scroll down to click on "Merge Cells". This will merge both rows and columns into one large cell, with alignment intact. ... .
This will merge the content of the upper-left cell across all highlighted cells..

Can you merge cells both vertically and horizontally?

Change Cell Alignment Select the cell(s) you want to align. To vertically align cells, click the vertical alignment button you want. To horizontally align cells, click the horizontal alignment button you want.