Merge cells in PHPExcel

September 29, 2013 | 9747 views | Comments

There's a function called mergeCells() in PHPExcel where rows and columns can be combined, this function will merge cells from a given column and row to a given column and row. The format of the parameter to be passed to the function is [START COLUMN][START ROW] : [END COLUMN][END ROW].

For example.

Merge from column A row 1 to column E row 1

$objPHPExcel->getActiveSheet()->mergeCells('A1:E1');

// add some text
$objPHPExcel->getActiveSheet()->setCellValue('A1','The quick brown fox.');

Result.

Please mouse over here to view the image.

Merge from column A row 1 to column E row 4

$objPHPExcel->getActiveSheet()->mergeCells('A1:E4');

// add some text
$objPHPExcel->getActiveSheet()->setCellValue('A1','The quick brown fox.');

Result.

Please mouse over here to view the image.