Merging cells in Excel by rows and columns together using PHPExcel

To merge cells in Excel using PHPExcel, you can use the mergeCells() method.

Syntax:

<?php

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

This example would merge the cells in the top left corner of the sheet (A1 and B2) into one cell. You can specify any range of cells to merge using the format 'A1:B2'.

Watch a course Learn object oriented PHP

To merge cells by rows and columns together you have to use the mergeCells method with the range of cells you want to merge.

<?php

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

This will merge cells from A1 to C3 in a sheet.