How can I set parts of the text font bold in one cell with loop within a loop

Topics: User Forum
Feb 24, 2015 at 6:59 PM
Edited Feb 24, 2015 at 7:10 PM
I have an error with PHPExcel Rich Text, when I have a loop and variables.
below part of my code.
foreach ($itens as $key => $a) {
        $objRichText = new PHPExcel_RichText();
        $texto = 'My ';
        $texto .= $i;
        $texto .= ' - some ' . $a. ' - lol';

        $objBold = $objRichText->createTextRun(sprintf("%s", $texto));
        $objBold->getFont()->setBold(true);

        $objNormal = $objRichText->createTextRun(' - ' . $a['something']);
        $aux = 14 + $key;
        $objPHPExcel->getActiveSheet()->getCell('G' . (STRING) $aux)->setValueExplicit($objRichText);
}
exemple output:
Image

And when the text is fixed functions normally as below
foreach ($itens as $key => $a) {
        $objRichText = new PHPExcel_RichText();
      
        $objBold = $objRichText->createTextRun('texto');
        $objBold->getFont()->setBold(true);

        $objNormal = $objRichText->createTextRun(' - something');
        $aux = 14 + $key;
        $objPHPExcel->getActiveSheet()->getCell('G' . (STRING) $aux)->setValueExplicit($objRichText);
}
help me please!!!
Coordinator
Feb 24, 2015 at 7:53 PM
Are you sure you're using
$objBold = $objRichText->createTextRun(sprintf("%s", $texto));
and not
$objBold = $objRichText->createTextRun('sprintf("%s", $texto)');
otherwise you've found a pretty fatal flaw in PHP itself, not simply in PHPExcel

Nor can I see the point in using sprintf("%s", $texto) instead of simply $texto
Feb 24, 2015 at 7:56 PM
on image I put $objBold = $objRichText->createTextRun('sprintf("%s", $texto)'); to teste.

the error is that began appearing these Japanese characters