I need to merge cells in Excel (xlsx) by rows and again by columns using PHPExcel. I tried the following.
$sheet->mergeCells(\"G\".($row_count+1).\":G\".($row
function cellsToMergeByColsRow($start = -1, $end = -1, $row = -1){
$merge = 'A1:A1';
if($start>=0 && $end>=0 && $row>=0){
$start = PHPExcel_Cell::stringFromColumnIndex($start);
$end = PHPExcel_Cell::stringFromColumnIndex($end);
$merge = "$start{$row}:$end{$row}";
}
return $merge;
}
Addition to the case:
$objPHPExcel->getActiveSheet()->mergeCells(cellsToMergeByColsRow(0,2,3))