phpexcelphpspreadsheetkartik-v

Yii2 Kartik Export with sub header


How to create multiple header (sub header) with kartik export, like table below sub header I guess using onRenderHeaderCell=>function($cell, $content, $widget){} function https://demos.krajee.com/export#option-onRenderHeaderCell, but still failed


Solution

  • I would not use headercells. I would format with plane formating commands. Something like this:

    $spreadsheet->getActiveSheet()->mergeCells('B1:C1');
    $spreadsheet->getActiveSheet()->mergeCells('F1:G1');
    $spreadsheet->getActiveSheet()->mergeCells('A1:A2');
    $spreadsheet->getActiveSheet()->mergeCells('D1:D2');
    $spreadsheet->getActiveSheet()->mergeCells('E1:E2');
    $spreadsheet->getActiveSheet()->getStyle("A1")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("B1")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("D1")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("E1")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("F1")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("B2")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("C2")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("F2")->getFont()->setBold(true);
    $spreadsheet->getActiveSheet()->getStyle("G2")->getFont()->setBold(true);
    

    Be carefull with merged cells. You should format die only the headcell.