How can I set parts of the text font bold in one cell

Topics: User Forum
Aug 24, 2011 at 7:29 AM

Hello:

Now suppose the text of cell A1 is 'Dear Amy,Thank you for using!'

I just want to set the font of text 'Dear Amy'  to be bold

What should I do.

Aug 24, 2011 at 10:57 AM
Edited Aug 24, 2011 at 10:59 AM

before you set the value into cell, write this

$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

Aug 24, 2011 at 11:01 AM

lemone:

Thank you for answer,

But I only want to set 'Dear Amy' to be bold except 'Thank you for using!'

And they are in the same cell

Aug 24, 2011 at 1:55 PM

You would do something like this...

$objRichText = new PHPExcel_RichText();

$objBold = $objRichText->createTextRun("Dear Amy");
$objBold->getFont()->setBold(true);

$objNormal = $objRichText->createTextRun(",Thank you for using!");

$data = $objRichText;

Aug 25, 2011 at 3:04 AM

Hello,ScottMSanders

Thank you for your answer.

I tried to use the coding which you have mentioned,but it didn't work. 

Maybe it does not support for Rich-Text in PHPExcel_Writer_Excel5

It means that I can not set the style like that in the same cell,doesn't it?


Aug 25, 2011 at 2:29 PM

Hmm, you're right -- I can only see the rich text in Excel 2007. :(

Aug 25, 2011 at 2:34 PM
Edited Aug 25, 2011 at 2:35 PM

Oh, here's why: http://phpexcel.codeplex.com/discussions/245615