PHPword表格中 单元格内输出不同样式的内容

注意 不能直接使用 

$table->addCell(2000)->addText('培训内容'.($i+1),$fontStyle);

要使用 addListItem 这个属性

$table = $section->addTable($styleTable);

$head = $DataOutput->head;

if ($head) {
    for ($i = 0; $i < count($head); $i++) {
        $h1 = '';
            $table->addRow();
                $table->addCell(2000)->addText('培训内容'.($i+1),$fontStyle);
                $cell = $table->addCell(8000);
                $data=  $head[$i]->cj;
                if($data){
                    $dataarr = $this->object_array($data);
                    $t=$head[$i]->ID;
                    $sot[$t]=($i+1);
                    foreach ($dataarr as $key=>$value)
                        $cell->addListItem($key.'<w:br/>',0,array('bold'=>true));
                        $h1.= $key.'<w:br/>' ;
                        for ($j=0;$j<count($dataarr[$key]);$j++){
                            $cell->addListItem($dataarr[$key][$j].'<w:br/>' ,1);
                            $h1.= $dataarr[$key][$j].'<w:br/>' ;
                        }
                }
        $cell->addListItem('安全管理员:'. ($head[$i]->SaftyManager?$head[$i]->SaftyManager:'无') .
            '   考核人:'. ($head[$i]->Examiner?$head[$i]->Examiner:'无') .
            '   授课人:'. ($head[$i]->Teacher?$head[$i]->Teacher:'无') ,0,array('bold'=>true));

        $cell->addListItem('学习方式:'. ($head[$i]->IsOnlineLearning?'线上培训':'现场培训') .
            '   时长:'. (ceil($head[$i]->Duration/60) .'分钟') .
            '   计划时间:'. $head[$i]->STime . ($head[$i]->IsOnlineLearning?' ~ '.$head[$i]->ETime:' ') ,0,array('bold'=>true));
    }

}

 

效果展示:

PHPword表格中 单元格内输出不同样式的内容

 

欢迎讨论,如有疑问 联系QQ524651703