PHPExcel - How to make part of the text bold

前端 未结 5 886
梦毁少年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:32

    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
        )
    );
    $sheet->getStyle('A1')->applyFromArray($styleArray);
    $writer = new PHPExcel_Writer_Excel5($workbook);
    header('Content-type: application/vnd.ms-excel');
    $writer->save('php://output');
    

    Hope this helps.

    Source

提交回复
热议问题