Merging cells in Excel by rows and columns together using PHPExcel

前端 未结 6 663
悲&欢浪女
悲&欢浪女 2021-02-05 10:25

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         


        
6条回答
  •  再見小時候
    2021-02-05 11:10

    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))
    

提交回复
热议问题