PHPExcel - How to make part of the text bold

前端 未结 5 892
梦毁少年i
梦毁少年i 2020-12-13 19:43

How do you create a bold cell value using PHPExcel? I know I can use \\n to add a carriage return within the text, but is there some kind of way to bold part of cell value?

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 20:18

    You can bold part of the text in a cell using rich text formatting, as described in section 4.6.37 of the developer documentation.

    $objRichText = new PHPExcel_RichText();
    $objRichText->createText('This text is ');
    
    $objBold = $objRichText->createTextRun('bold');
    $objBold->getFont()->setBold(true);
    
    $objRichText->createText(' within the cell.');
    
    $objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
    

提交回复
热议问题