PHPExcel-如何使文本的一部分变为粗体 [英] PHPExcel - How to make part of the text bold

查看:606
本文介绍了PHPExcel-如何使文本的一部分变为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHPExcel创建粗体单元格值?我知道我可以使用\ n在文本内添加回车符,但是是否有某种方式可以对单元格值的部分进行加粗显示?我也尝试使用html格式,例如< b>或< strong>但这没用.

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.

推荐答案

您可以使用富文本格式将单元格中的部分文本加粗,如开发人员文档的4.6.37节所述.

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

这篇关于PHPExcel-如何使文本的一部分变为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆