bolding words on text

Topics: User Forum
May 12, 2011 at 8:40 AM

guys, how can I bolding word on text like this:

$to_bold = "love";

$text = "I love people who love me and love every one";

result that i want is: 

I love people who love me and love every one

 

thanks for any help..

May 13, 2011 at 10:37 AM

You can try Add rich-text string

Best example file is 05featuredemo.php

May 14, 2011 at 4:00 PM

thx pak_slm. yes Ive read that demo, but cant figure out how to do that. so you suggest me to concanate rich-text string to produce that?

how if $to_bold is dynamic variable? how could I bolding text from dynamic variable?

Jun 9, 2011 at 3:21 PM

 

 

<?
error_reporting(E_ALL);
require_once '../Classes/PHPExcel.php';
require_once '../Classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex(0);

$objRichText = new PHPExcel_RichText( $objPHPExcel->getActiveSheet()->getCell('A1') );

$btext = 'love';
$str = "I love people who love me and love every one";
$textbold = explode(' ',$str);

$strout="";
for ( $i = 0; $i < count($textbold); $i++) { 
	$objPayable = $objRichText->createTextRun($textbold[$i].' ');
	if($textbold[$i] == $btext){
		$objPayable->getFont()->setBold(true);
	}
} 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="bold.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 
exit;
?>

 

 

Jun 23, 2011 at 1:02 AM
Edited Jun 23, 2011 at 1:05 AM
pak_slm wrote:

 

 

<?
error_reporting(E_ALL);
require_once '../Classes/PHPExcel.php';
require_once '../Classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex(0);

$objRichText = new PHPExcel_RichText( $objPHPExcel->getActiveSheet()->getCell('A1') );

$btext = 'love';
$str = "I love people who love me and love every one";
$textbold = explode(' ',$str);

$strout="";
for ( $i = 0; $i < count($textbold); $i++) { 
	$objPayable = $objRichText->createTextRun($textbold[$i].' ');
	if($textbold[$i] == $btext){
		$objPayable->getFont()->setBold(true);
	}
} 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="bold.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 
exit;
?>

 

 

Sorry, this doesn't work....

It show "I love  people who love   me and love   every one"

not "I love people who love me and love every one"

Jun 23, 2011 at 6:56 AM

Not possible,

i have test again and it giving required output at cell A1.