Merging cells in Excel by rows and columns together using PHPExcel

前端 未结 6 675
悲&欢浪女
悲&欢浪女 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:21

    I make a simple function to calc cells to merge by cols and row.

    function cellsToMergeByColsRow($start = NULL, $end = NULL, $row = NULL){
        $merge = 'A1:A1';
        if($start && $end && $row){
            $start = PHPExcel_Cell::stringFromColumnIndex($start);
            $end = PHPExcel_Cell::stringFromColumnIndex($end);
            $merge = "$start{$row}:$end{$row}";
    
        }
    
        return $merge;
    }
    

    And call

    $sheet->mergeCells(cellsToMergeByColsRow($col, $col+5, $row));
    

    Thanks @Mark Baker

提交回复
热议问题