使用PHPExcel在1个单元格内设置不同的字体颜色 [英] Set different font-color inside 1 cell using PHPExcel

查看:1271
本文介绍了使用PHPExcel在1个单元格内设置不同的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHPExcel使文本在1个单元格内具有不同的颜色,但是我找不到有关它的信息.有可能吗?

I want to make the text have different color inside 1 cell using PHPExcel, but i can't find the info about it. Is it possible?

我相信它可以通过xls完成,但是可以使用PHPExcel中的编程来完成吗?

I believe it can be done from the xls, but can it be done using programming, in PHPExcel?

推荐答案

是的,可以使用Rich Text对象在PHPExcel中完成.

Yes it can be done in PHPExcel, using Rich Text objects.

它们在提供了示例

$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor(
    new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN )
);
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);

这篇关于使用PHPExcel在1个单元格内设置不同的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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