Merging cells in Excel by rows and columns together using PHPExcel

前端 未结 6 728
悲&欢浪女
悲&欢浪女 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 was also looking solution for this question. where i want to merge cell and put content (value) on that. After few search i got some solution on this. but did not checked because i am using Maatawebsite for get Excel file.

    But any one can try thing.. Solution is based on PHPExcel nit sure ,it will work on Maatawebsite.

    Source Link

    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.'); 
    

    Merge from column A row 1 to column E row 3

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

    I checked maatawebsite document and they have same method mergeCells. so i think i would be work.

    This Solution from Maatawebste.

    $sheet->cells('A1:C1', function($cells) {
        $cells->setBorder('thin', 'thin', 'thin', 'thin');
    });
    $sheet->mergeCells('A1:C1');
    

    Solution 2nd

    $sheet->setMergeColumn(array(
    'columns' => array('A','B','C','D'),
    'rows' => array(
    array(2,3),
    array(5,11),
    )
    ));
    

提交回复
热议问题