[Solved] PHPExcel – How to make part of the text bold

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? I also have tried using html formatting such as <b> or <strong> but it did not work.

Solution #1:

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

$objRichText->createText(' within the cell.');

Respondent: Mark Baker

Solution #2:

Yes you can bold a cell’s value with the following code:

$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World');
$styleArray = array(
    'font' => array(
        'bold' => true
$writer = new PHPExcel_Writer_Excel5($workbook);
header('Content-type: application/vnd.ms-excel');

Hope this helps.


Respondent: Eric LaForce

Solution #3:

            ->setCellValue('A1', 'Hello')
            ->setCellValue('B1', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D1', 'world!');

for single cell use:


for multiple cells use:

Respondent: Ashwin

Solution #4:

You can use the HTML helper class in PHPExcel to bold text.

$htmlHelper = new PHPExcel_Helper_HTML();
$html = "<b> Bold Text!! </b>";
$rich_text = $htmlHelper->toRichTextObject($html);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $rich_text);
Respondent: Syam

Solution #5:

Respondent: Nishant

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.